ericburnard Posted August 20, 2011 Share Posted August 20, 2011 Back again!! I have been trying to think of a way to do this but its starting to make my brain itch a bit too much now!!! I have the code below to display my query. Basicly its to disply 3 images and when 'x=a multiple of 3' it ends the row and starts another. The only problem is, that the first result will not be displayed as x has to begin at 1. if x begins at 0, it will display the first result and begin a new line. echo "<center><table border='0' cell padding='3'><tr>"; $x = 1; while ($x < $num) { $id=mysql_result($result,$x,"id"); $caption=mysql_result($result,$x,"cap"); $address=mysql_result($result,$x,"address"); $date=mysql_result($result,$x,"date"); $album=mysql_result($result,$x,"album"); $member=mysql_result($result,$x,"member"); echo "<td><center><img src='/images/uploads/main/thumb_".$address."'><br>$caption</center></td>"; echo ($x % 3 == 0)? "</tr><tr>" : ""; $x++; } echo "</tr></table>"; Can anyone point me in the right direction?? Thanks Eric Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/ Share on other sites More sharing options...
silkfire Posted August 20, 2011 Share Posted August 20, 2011 Why can't you init $x = 0 instead of 1? Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1259958 Share on other sites More sharing options...
ericburnard Posted August 20, 2011 Author Share Posted August 20, 2011 If i have $x = 0 then the code echo ($x % 3 == 0)? "</tr><tr>" : ""; will equal 0 which means it will start a new row. So i will have 1 image on the first row and then 3 on all the others Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1259959 Share on other sites More sharing options...
silkfire Posted August 21, 2011 Share Posted August 21, 2011 just add && $x != 0 there Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1260131 Share on other sites More sharing options...
jcbones Posted August 21, 2011 Share Posted August 21, 2011 If you look at the manual http://php.net/manual/en/function.mysql-result.php You would find that you are NOT getting the first row in your results, because that first row starts at 0. So you will have to start $x = 0; Then change: echo ($x % 3 == 0)? "</tr><tr>" : ""; To echo ($x > 0 && ($x % 3 == 0))? "</tr><tr>" : ""; Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1260136 Share on other sites More sharing options...
ericburnard Posted August 21, 2011 Author Share Posted August 21, 2011 But surely that world give you 4 results on the first row and the 3 on all the others?! Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1260168 Share on other sites More sharing options...
silkfire Posted August 21, 2011 Share Posted August 21, 2011 Eric you need to go study some basic logic. Programming is logic and maths. Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1260195 Share on other sites More sharing options...
teynon Posted August 21, 2011 Share Posted August 21, 2011 ericburnard, study like others said, but: Init x to 0, then in your if do this: echo (($x+1) % 3 == 0)? "</tr><tr>" : ""; Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1260197 Share on other sites More sharing options...
ericburnard Posted August 21, 2011 Author Share Posted August 21, 2011 I will go study =) Ive only ever learnt from bits and bobs that ive needed at the time so really i should learn things properly! This is what i came up with before i saw the new posts $num2=$num+1; echo "<center><table border='0' cell padding='3' class='small'><tr>"; $x = 0; $xp = 1; while ($xp < $num2) { $id=mysql_result($result,$x,"id"); $caption=mysql_result($result,$x,"cap"); $address=mysql_result($result,$x,"address"); $date=mysql_result($result,$x,"date"); $album=mysql_result($result,$x,"album"); $member=mysql_result($result,$x,"member"); echo "<td><center><a href='?p=album&album=$album'><img src='/images/uploads/main/thumb_".$address."'></a><br><a href='?p=album&album=$album'>$album</a><br> Last Updated on $date By $member</center></td>"; echo (($xp % 2 == 0) && $xp != 0)? "</tr><tr>" : ""; $xp++; $x++; } echo "</tr></table>"; Quote Link to comment https://forums.phpfreaks.com/topic/245313-how-to-display-value-0-in-the-row/#findComment-1260202 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.