Jump to content


Photo

trouble displaying query results in the same row


  • Please log in to reply
2 replies to this topic

#1 speals

speals
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 October 2006 - 08:13 PM

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.
<?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>

";
}
?>


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 08 October 2006 - 08:24 PM

Something like this?

<?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>";

?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 speals

speals
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 October 2006 - 11:55 PM

Thank you so much. Was able to play with it and got exactly what I needed.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users