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] Link to comment https://forums.phpfreaks.com/topic/23377-trouble-displaying-query-results-in-the-same-row/ 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. Link to comment https://forums.phpfreaks.com/topic/23377-trouble-displaying-query-results-in-the-same-row/#findComment-105982 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. Link to comment https://forums.phpfreaks.com/topic/23377-trouble-displaying-query-results-in-the-same-row/#findComment-106033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.