I'm trying to pull data out of a MySQL DB and show it on a php page. I would like to show all entries for a particular column, but every example I try either doesn't work, or this one shown below, that only shows 1. I'm thinking maybe I can loop or add another $row, but Im not sure. There could potantialy be a lot of entries, so im guessing it wiould need to loop until the end.
$result = mysql_query("SELECT name FROM s_users WHERE rank = 1 LIMIT 0 , 30") or die(mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $sl = $row['name'];
When that's echo'd it only shows 1 entry, when the db is showing several names that fit the criteria.. Is there also a way to show them in a row with comma seperators? name1, name2, name3...
PHPMySQL Server
Last Comment
Ray Paseur
8/22/2022 - Mon
maeltar
You need to itterate through the query results :
$result = mysql_query("SELECT name FROM s_users WHERE rank = 1 LIMIT 0 , 30") or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ // $sl = $row['name']; echo $row['name'] . "<br />";}
Hello, I tried the suggestion but this way its still only pulling out one name at a time.
The example you provided earlier pulled out multiple names, but stacked them vertically, so I know they are in there, Im just not having any luck dragging them out. Below is the full function.
If you run that script segment and find only one name in the results set, you can be fairly sure that there is only one row in s_users that satisfied the WHERE clause.
Open in new window