Jump to content

[SOLVED] Putting in line breaks in a while loop?


JJohnsenDK

Recommended Posts

hey

 

im trying to run a while loop that puts in breaks (<br />) when 3 pictures have been displayed.

 

<?php
while($catListRow = mysql_fetch_array($searchQuery)){
echo "<p><a href='gallery.php?action=3&no=".$catListRow['download_id']."&cat=".$catListRow['download_cat']."'><img src='".$catListRow['download_url']."' height='100' alt='".$catListRow['download_title']."' /></a></p>";
}
?>

 

as the code are at the moment it just prints out all the pictures in one long line. How do i get the script to put in a line break everytime 3 pictures have been printed?

<?php
$_num = 0
while($catListRow = mysql_fetch_array($searchQuery))
{
echo "<p><a href='gallery.php?action=3&no=".$catListRow['download_id']."&cat=".$catListRow['download_cat']."'><img src='".$catListRow['download_url']."' height='100' alt='".$catListRow['download_title']."' /></a></p>";
$_num++;
if ($_num == 3)
{
echo "<br>";
}
}
?>

Untested

Only one thing I would add. If you want to display more than 6 pictures and need more breaks then you need to reset the counter to 0 when you add the break.

 

<?php

$_num = 0

while($catListRow = mysql_fetch_array($searchQuery))

{

echo "<p><a href='gallery.php?action=3&no=".$catListRow['download_id']."&cat=".$catListRow['download_cat']."'><img src='".$catListRow['download_url']."' height='100' alt='".$catListRow['download_title']."' /></a></p>";

$_num++;

if ($_num == 3)

{

echo "<br>";

$_num = 0;

}

}

?>

 

 

Snowdog

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.