Jump to content

Archived

This topic is now archived and is closed to further replies.

speals

trouble displaying query results in the same row

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thank you so much. Was able to play with it and got exactly what I needed.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.