Skip to main content
Inspiring
July 29, 2007
Answered

Nested repeat and horizontal loop, I think?

  • July 29, 2007
  • 4 replies
  • 714 views
Nested repeat and horizontal loop, I think as I am stuck on a small issue with a nested repeat region which is needed and looping through it horizontally with or without tables.

Like 2 or 3 per columns but horizontally?
==========================
Categoryname1
Image //for this category
Image //for this category
==========================
Categoryname2
Image //for this category
Image //for this category
==========================
Is there anything for this as I am pulling my hair out over this one?
Thanks in advance!
This topic has been closed for replies.
Correct answer MikeL7
IF(language = PHP) {
This is a really good bit of code i got from someone here, what it does is display the results of a recordset horizontally, i used it for displaying thumbnails, with some modification you could probably make it work how you want. The $cols variable sets the number of columns per row. Substitute your recordset and change the variables and it should work

//START CODE BLOCK
$picturelocsql = "SELECT images.img_id, images.description, images.name, images.location, images.upload_date, albums.album_name FROM images, albums WHERE albums.id = images.album_id AND user_id = " . $_SESSION['SESS_USERID'] . " ORDER BY location ASC;";
$picturelocres = mysql_query($picturelocsql);


echo "<table cellpadding='10'><tr>";
$pos = 0;
$cols = 3;

while ($picloc = mysql_fetch_assoc($picturelocres)) {
$pos++;


$mainpic .= "<td><a href='imageview.php?picid=" . $picloc['img_id'] . "'><img src='pics/" . $picloc['name'] . "' alt='" . stripslashes($picloc['description']) . "... Date: " . date("D F jS, Y", strtotime($picloc['upload_date'])) . "'></a><br />Album: " . $picloc['album_name'] . "</td>";//this is the part you would mod to display your way

if ($pos%$cols === 0 && is_array($picloc)) {
$mainpic .= '</tr><tr>';
}
}
while ($pos%$cols) {
$mainpic .= '<td> </td>';
$pos++;
}
echo $mainpic;
echo "</tr></table>";
}
//END CODE BLOCK
} else {
try something similar in your language
}

4 replies

MikeL7Correct answer
Inspiring
August 7, 2007
IF(language = PHP) {
This is a really good bit of code i got from someone here, what it does is display the results of a recordset horizontally, i used it for displaying thumbnails, with some modification you could probably make it work how you want. The $cols variable sets the number of columns per row. Substitute your recordset and change the variables and it should work

//START CODE BLOCK
$picturelocsql = "SELECT images.img_id, images.description, images.name, images.location, images.upload_date, albums.album_name FROM images, albums WHERE albums.id = images.album_id AND user_id = " . $_SESSION['SESS_USERID'] . " ORDER BY location ASC;";
$picturelocres = mysql_query($picturelocsql);


echo "<table cellpadding='10'><tr>";
$pos = 0;
$cols = 3;

while ($picloc = mysql_fetch_assoc($picturelocres)) {
$pos++;


$mainpic .= "<td><a href='imageview.php?picid=" . $picloc['img_id'] . "'><img src='pics/" . $picloc['name'] . "' alt='" . stripslashes($picloc['description']) . "... Date: " . date("D F jS, Y", strtotime($picloc['upload_date'])) . "'></a><br />Album: " . $picloc['album_name'] . "</td>";//this is the part you would mod to display your way

if ($pos%$cols === 0 && is_array($picloc)) {
$mainpic .= '</tr><tr>';
}
}
while ($pos%$cols) {
$mainpic .= '<td> </td>';
$pos++;
}
echo $mainpic;
echo "</tr></table>";
}
//END CODE BLOCK
} else {
try something similar in your language
}
Inspiring
August 7, 2007
thanks
Inspiring
August 8, 2007
Glad that it worked for you, someone else helped with that bit and so i passed it on to you. The thing a liked about it is you can make the table how ever you want. If you were wondering about the location order by i made it so the user can put 12 thumbnails they choose and change their location on their home page.
August 7, 2007
Thanks for the link, Unfortunately that doesn't do what I need. The Simulated Nested Region extension is a little closer but very unstable and hard to control the result unless you do only what the example shows.

Dave
August 6, 2007
did you ever get an answer for this? I could use the answer here also
Thanks
Inspiring
July 29, 2007
bump...