简体   繁体   中英

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". 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.

As for displaying buttons/workouts. You can embed HTML code inside the echo statement like below. You can add any html like that and it will render 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>";
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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