Jump to content

How to display value 0 in the row


ericburnard

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.