speals Posted October 8, 2006 Share Posted October 8, 2006 Hi. I am trying to display all my data in table format with the first five results in the first row, the next five in the second row, ect. Right now it displays the first result five times in the first row, the second result five times in the second row, etc. How can I write the loop to have it display each result one time? Thank you for your time. [code]<?php$Host = "localhost";$User = "";$Password = "";$mydatabase = "fashion";$db = mysql_connect("$Host", "$User", "$Password") or die ("Couldnt connect to the server.");mysql_select_db ("$mydatabase",$db) or die ("Couldnt select the database. ".mysql_error());$result = mysql_query("select * from pictures");while ($myrow = mysql_fetch_row($result)) {echo " <table cellSpacing=0 cellPadding=10 width=90% border=0 hspace=0 vspace=0> <tr valign = top align=center> <td><img POSITION: absolute; src='$myrow[2]' hspace=0 border=0></img></td> <td><img POSITION: absolute; src='$myrow[2]' hspace=0 border=0></img></td> <td><img POSITION: absolute; src='$myrow[2]' hspace=0 border=0></img></td> <td><img POSITION: absolute; src='$myrow[2]' hspace=0 border=0></img></td> <td><img POSITION: absolute; src='$myrow[2]' hspace=0 border=0></img></td> </tr> <tr align=center> <td>$myrow[1]</td> <td>$myrow[1]</td> <td>$myrow[1]</td> <td>$myrow[1]</td> <td>$myrow[1]</td> </tr> </table>";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Orio Posted October 8, 2006 Share Posted October 8, 2006 Something like this?[code]<?php$result = mysql_query("select * from pictures");echo("<table cellSpacing=0 cellPadding=10 width=90% border=0 hspace=0 vspace=0>");$i=1;while ($myrow = mysql_fetch_row($result)) {if($i%5==0) echo "<tr valign = top align=center>";echo "<td><img POSITION: absolute; src='$myrow[2]' hspace=0 border=0></img></td>";echo "<td>$myrow[1]</td>";if($i%5==0) echo "</tr>";$i++;}echo "</table>";?>[/code]Orio. Quote Link to comment Share on other sites More sharing options...
speals Posted October 8, 2006 Author Share Posted October 8, 2006 Thank you so much. Was able to play with it and got exactly what I needed. 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.