Jump to content

Recommended Posts

I'm building a photo gallery table of X rows and 8 columns/pictures wide based on the numer of images in the database.  Having a brain-freeze though and can't get it to create additional rows.  Also, the ending table row tag is nesting properly.  Logic problem maybe?  Thanks for any help. 

 

$sql="SELECT * FROM uploads WHERE (userID LIKE '%$searchString%') OR (alt LIKE '%$searchString%') OR (date LIKE '%$searchString%') OR (store LIKE '%$searchString%');";
				$result=mysql_query($sql);
				$num=mysql_numrows($result);
				$i=0;

				$rows=0;
				while($rows<=$num/8){

						echo"<tr>";

						while ($i < $num  && $pictureCount <= 7)
						{
							$fname=mysql_result($result,$i,'filename');
							$username=mysql_result($result,$i,'userID');
							$store=mysql_result($result,$i,'store');
							$date=mysql_result($result,$i,'date');
							$altText=mysql_result($result,$i,'alt');

							echo"
								<td>
									<img src='$url/contribute/upload/image.php?width=75&height=75&cropratio=1:1&image=$url/contribute/upload/$fname' alt='$altText' />
								</td>
							";

							$i++;
							$pictureCount++;
						}
						echo"</tr>";
					$rows++;
				}

Link to comment
https://forums.phpfreaks.com/topic/239447-building-a-table-from-loop/
Share on other sites

This is what I've got so far.

 

$result=mysql_query($sql);
$num=mysql_numrows($result);
$i=0;


for($rowNum=1; $rowNum<=$num/8;$rowNum++){
echo"<tr>";

    for($colNum=1; $colNum<=8;$colNum++){

        while ($i < $num){
             $fname=mysql_result($result,$i,'filename');
             $altText=mysql_result($result,$i,'alt');

         echo"
<td>
     <img src='$url/...alt='$altText' />
</td>
          ";
           $i++;
        }
        echo"</tr>";
}
}

 

However, the table row tags are being put at the end of code-and not with 8 column tags within them. 

 

Shouldnt this way work as well?

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.