smc Posted January 29, 2007 Share Posted January 29, 2007 Okay, I've been trying to do this for a while but I never succeed and end up doing a work around to solve my problem. I'm tired of that, time to stare PHP/MySQL in the eye and say FETCH THAT ARRAY!Basically heres the deal.I want to call everything in my database within an HTML page that meets a specific MySQL critera ( WHERE status = 'pending' ) . I want to then echo all of those in a table format. This means I would need to generate a new table (or row) [In HTML] for all of these entries MySQL found.I tried this:[code]function listusers() {//Query for execution$fetchfido = mysql_query('SELECT * FROM `users` ORDER BY `users` . `username` ASC');//While we are grabbing the array we will go ahead and prep the HTML for echoingwhile($users = mysql_fetch_array($fetchfido)){ $listusers = "<a href=\"/admin/admin_users.php?user=$users[username]\">$users[username]</a><br />";}}[/code]But it only echoed the last row. Snafo.Any help you can offer for me to battle this tourmenter would be much appreciated!!Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/36127-solved-fetch-multiple-rows-and-echo/ Share on other sites More sharing options...
spfoonnewb Posted January 29, 2007 Share Posted January 29, 2007 Few small changes, but it should work.. or it'll tell you the error. I think it only echo's 1 because there is only 1 $listusers.[code]<?phpfunction listusers() {$result = mysql_query("SELECT * FROM `users` ORDER BY `users`, `username` ASC") or die(mysql_error());while($row = mysql_fetch_array( $result )) {echo "<a href=\"/admin/admin_users.php?user=$users[username]\">".$row['username']."</a><br />";}}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36127-solved-fetch-multiple-rows-and-echo/#findComment-171548 Share on other sites More sharing options...
kevinkorb Posted January 29, 2007 Share Posted January 29, 2007 What you are doing is correct.however that won't output anything, it just puts it in a variable...but to create your table you'd just need.[code=php:0]<?php$query = "YOUR QUERY";$result = mysql_query($query);echo "<table>\n";while($row = mysql_fetch_assoc($result)) { echo "<tr><td>{$row['field_1']}</td><td>{$row['field_2']}</td></tr>\n";}echo "</table>\n";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36127-solved-fetch-multiple-rows-and-echo/#findComment-171549 Share on other sites More sharing options...
smc Posted January 30, 2007 Author Share Posted January 30, 2007 I'm not sure what to do. Both of those only echo my result once.Does anyone have any tips for acomplishing what I need to accomplish? Quote Link to comment https://forums.phpfreaks.com/topic/36127-solved-fetch-multiple-rows-and-echo/#findComment-173160 Share on other sites More sharing options...
boo_lolly Posted January 31, 2007 Share Posted January 31, 2007 i don't see what the problem is...[code]<?php $sql = "SELECT * FROM users WHERE status = 'pending' ORDER BY username ASC"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ echo "<a href=\"/admin/admin_users.php?user=". $row['username'] ."\">". $row['username'] ."</a><br />\n"; }?>[/code]you may need to add return; to the end of your function too. try that query and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/36127-solved-fetch-multiple-rows-and-echo/#findComment-173266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.