Jump to content

Building a table from loop


hdbrandon

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.