Hi all, When I ouput my query to the page I want it listed in a table like this- TABLE result1 result2 result3 result4 result5 result6 The script displays 5 results only. Script - <? $sql="select * from members,photos where members.username=photos.username and active=1 and approved='Y' ORDER BY UPLDATE DESC LIMIT 2, 5"; $result = mysql_query($sql); $res=mysql_query($sql); while($obj=mysql_fetch_object($res)) { if($obj->url=="") { $img="<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>"; } else { $img="<a target='_blank' href='$obj->url'><img border=0 width=100 height=100 src='$obj->url'></a>"; } $id=$obj->photosid; $username=$obj->username; ?> <? print $img; ?><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<? print $username; ?>">View<? print $username; ?> profile</a> <? } if($count!=0) { ?> <? } ?> PHP:
The LIMIT 2, 5 in the sql statement will limit the amount that is returned you want 6 you should make it return 6 starting from mysql entry 2. 2, 6; . I do not see any table formating in the output. Have you tried to do the table structure for it? <?php $sql = "select * from members,photos where members.username = photos.username and active = 1 and approved = 'Y' ORDER BY UPLDATE DESC [B]LIMIT 2, 6[/B]"; $res = mysql_query($sql); while ($obj = mysql_fetch_object($res)) { $id = $obj->photosid; $username = $obj->username; if ($obj->url == "") { $img = "<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>"; } else { $img = "<a target='_blank' href='$obj->url'><img border=0 width=100 height=100 src='$obj->url'></a>"; } ?> <?php print $img; ?><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<?php print $username; ?>">View<?php print $username; ?> profile</a> <?php } if ($count != 0) { ?> PHP:
<table border="1" cellpadding="0" cellspacing="0"> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table> Code (markup): That is a table like you want. So, basicly you need to use a counter to count up to two for each loop of the information and then output a </tr><tr> and then set the counter back to zero after you have done that. Put the table outside the while statement and put the </table> bottom of the while statement. At least that is what I end up doing. You could also use <div> floating left and right then clear. Output 1-X in the float left and when the counter hit that amount then output the x-6 in the right float and then just clear both floats and then do it that way. <?php $sql = "select * from members,photos where members.username = photos.username and active = 1 and approved = 'Y' ORDER BY UPLDATE DESC LIMIT 2, 6"; $res = mysql_query($sql); echo "<table><tr>"; while ($obj = mysql_fetch_object($res)) { $id = $obj->photosid; $username = $obj->username; if ($obj->url == "") { $img = "<a target='_blank' href='../pics/$obj->filename'><img border=0 width=100 height=100 src='../pics/$obj->filename'></a>"; } else { $img = "<a target='_blank' href='$obj->url'><img border=0 width=100 height=100 src='$obj->url'></a>"; } ?> <?php echo "<td>"; print $img; ?><a href="http://www.pictures2rate.com/index.php?cmd=20&username=<?php print $username; ?>">View<?php print $username; ?> profile</a></td> <?php $count++; if($count == 2) { echo "</tr><tr>"; $count = 0;} } echo "</tr></table>"; if ($count != 0) { ?> PHP: