Skip to main content
Inspiring
February 14, 2007
Question

Programmatical unordered lists - PHP

  • February 14, 2007
  • 12 replies
  • 621 views
I have this code to write a recordset into adjacent sets of unordered lists,
each containing 5 list elements -

<ul>
<?php $i=0; do { ?>
<li><a href="p7hg_img_1/fullsize/<?php echo
$row_Recordset1['imgsFilename']; ?>_fs.jpg"><img
src="p7hg_img_1/thumbs/<?php echo $row_Recordset1['imgsFilename'];
?>_tmb.jpg" alt="Gallery: Image" title="" width="100" height="67"></a>
<div><?php echo $row_Recordset1['imgsCaption'];
?></div>
</li>
<?php $i++; if ($i==5) { $i=0; echo '</ul><ul>'; } ?>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</ul>

The problem comes when the looper terminates. I am left with a spare
<ul></ul> pair. How can I manage this?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================



This topic has been closed for replies.

12 replies

Inspiring
February 14, 2007
That looks great. I'll give it a try!

Thanks a million.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Gary White" <gary@apptools.com> wrote in message
news:ca95t25aaso285pvo9qjai8lmo63hg42i3@4ax.com...
> On Tue, 13 Feb 2007 20:17:58 -0500, "Murray *ACE*"
> <forums@HAHAgreat-web-sights.com> wrote:
>
>>The problem comes when the looper terminates. I am left with a spare
>><ul></ul> pair. How can I manage this?
>
>
> Try something like this:
>
> <?php
> $tmplt='<li><a href="p7hg_img_1/fullsize/%s_fs.jpg">'.
> '<img src="p7hg_img_1/thumbs/%s_tmb.jpg" alt="Gallery: '.
> 'Image" title="" width="100" height="67"></a>'.
> '<div>%s</div></li>'."\n";
> $i=0; do {
> if($i%5==0)
> print "<ul>\n";
> printf($tmplt,$row_Recordset1['imgsFilename'],
> $row_Recordset1['imgsFilename'],$row_Recordset1['imgsCaption']);
> $i++;
> if($i%5==0)
> print "</ul>\n";
> } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
> if($i%5!=0)
> print "</ul>\n";
> ?>
>
> Gary


Inspiring
February 14, 2007
On Tue, 13 Feb 2007 20:17:58 -0500, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>The problem comes when the looper terminates. I am left with a spare
><ul></ul> pair. How can I manage this?


Try something like this:

<?php
$tmplt='<li><a href="p7hg_img_1/fullsize/%s_fs.jpg">'.
'<img src="p7hg_img_1/thumbs/%s_tmb.jpg" alt="Gallery: '.
'Image" title="" width="100" height="67"></a>'.
'<div>%s</div></li>'."\n";
$i=0; do {
if($i%5==0)
print "<ul>\n";
printf($tmplt,$row_Recordset1['imgsFilename'],
$row_Recordset1['imgsFilename'],$row_Recordset1['imgsCaption']);
$i++;
if($i%5==0)
print "</ul>\n";
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if($i%5!=0)
print "</ul>\n";
?>

Gary