jakatu Posted June 16, 2008 Share Posted June 16, 2008 I am trying to call each record in a user database table and display them in a member directory for my site and I only get the first users information for every record in my table. <?php $query = "SELECT id FROM users ORDER BY company ASC"; $result = mysql_query($query); confirm_query($result); $row = mysql_fetch_array($result); foreach($row as $id){ $query = "SELECT name, address, city, state, zip, phone, fax, email, company FROM users WHERE id = $id"; $result = mysql_query($query); confirm_query($result); $row = mysql_fetch_array($result); $name = $row['name']; $email = $row['email']; $company = $row['company']; ?> <td valign="top" style="font-size:12px; text-align:center"> <table> <tr> <td><?php echo $name; ?></td> </tr> <tr> <td><?php echo $company; ?></td> </tr> <tr> <td><?php echo $email; ?></td> </tr> </table> </td> <? } ?> I have tried doing a while loop and get the right id numbers back from the initial query but I have frankly never been able to get foreach right and I just want to finally do it. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/110456-foreach-loop-reiterating-the-same-record-in-an-array/ Share on other sites More sharing options...
rhodesa Posted June 16, 2008 Share Posted June 16, 2008 <?php $query = "SELECT id, name, address, city, state, zip, phone, fax, email, company FROM users ORDER BY company ASC"; $result = mysql_query($query); confirm_query($result); while($row = mysql_fetch_array($result)){ $name = $row['name']; $email = $row['email']; $company = $row['company']; ?> <td valign="top" style="font-size:12px; text-align:center"> <table> <tr> <td><?php echo $name; ?></td> </tr> <tr> <td><?php echo $company; ?></td> </tr> <tr> <td><?php echo $email; ?></td> </tr> </table> </td> <? } ?> Link to comment https://forums.phpfreaks.com/topic/110456-foreach-loop-reiterating-the-same-record-in-an-array/#findComment-566698 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.