PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm trying to while() loop 20 rows of data in MySQL. I want it to be displayed in a table using the while() loop, yet when I use it, it just repeats the same line over and over again. How can I fix this? (the table is already declared)
Well, because you are running a new query each time through the loop so you always get the first record. Just query once and then fetch a new row from the query result each time through the loop:
$result = $db->query_read("SELECT * FROM quote ORDER BY id ASC");
while($quote_list_result = $db->fetch_array($result)) {
echo('<tr>');
echo('<td>' . $quote_list_result['author'] . '</td>');
echo('<td>' . $quote_list_result['text'] . '</td>');
echo('</tr>');
}
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.