简体   繁体   English

我如何选择和显示来自同一用户的所有行,而在彼此之间却是php

[英]how can I select and display all the rows from the same user, underneath each other with php

Users can add their workouts into a database. 用户可以将他们的锻炼添加到数据库中。 There will have more than one workout per user. 每个用户将进行一次以上的锻炼。 How can i display the workout names for the logged in user, underneath each other? 如何在彼此下方显示已登录用户的锻炼名称? I have no problem adding the workouts. 我没有添加锻炼的问题。 When I echo the names of the added workouts, it display right next to each other like "workout1workout2". 当我回显添加的锻炼的名称时,它会像“ workout1workout2”一样紧挨显示。 I want to be able to display the workouts underneath each other. 我希望能够在彼此下方显示锻炼。 I have no idea how to do it. 我不知道该怎么做。 It would be best if I could display each workout as a button. 最好将每个锻炼显示为一个按钮。

$query = "SELECT * FROM info WHERE username='$_SESSION[username]' ";
$results = mysqli_query($db, $query);
while($data = mysqli_fetch_array($results)) {
    echo $data['workout'];
}

$ query =“ SELECT * FROM info WHERE用户名='$ _ SESSION [用户名]'用户名分组”

Firstly, you shouldn't put that username in query like that. 首先,您不应该这样输入用户名。 Look into SQL Injection and how to avoid that in PHP. 了解SQL注入以及如何在PHP中避免这种情况。

As for displaying buttons/workouts. 至于显示按钮/锻炼。 You can embed HTML code inside the echo statement like below. 您可以将HTML代码嵌入到echo语句中,如下所示。 You can add any html like that and it will render HTML. 您可以添加任何类似的html,它将呈现HTML。

   $query = "SELECT * FROM info WHERE username='$_SESSION[username]' ";
   $results = mysqli_query($db, $query);
   while($data = mysqli_fetch_array($results)) {
   echo "<button>$data['workout']</button></br>";
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM