AbydosGater Posted September 23, 2006 Share Posted September 23, 2006 Hi, I know how to use a basic foreach loop.. ie:foreach ($item as $value){statment here};But how would i evolve this to work with rows in a database?say if i wanted to display info from my database rows in a list? what would i set the $item to?Could anyone help me please ive been trying to do this for weeks and just cant get it to work!Thanks Abydos Quote Link to comment Share on other sites More sharing options...
shocker-z Posted September 23, 2006 Share Posted September 23, 2006 $query=mysql_uery("SELECT * FROM table");while ($row=mysql_fetch_array($query) {//$row['ID'] would return the Id from that row};That's how most people loop thru mysql dataRegardsLiam Quote Link to comment Share on other sites More sharing options...
Barand Posted September 23, 2006 Share Posted September 23, 2006 try[code]<?php$query = mysql_query("SELECT * FROM table");echo "<table border='1'>\n";while ($row=mysql_fetch_assoc($query)) { echo '<tr>'; foreach ($row as $field) { echo "<td>$field</td>"; } echo "</tr>\n";}echo "</table>\n";?>[/code] Quote Link to comment 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.