close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Splitting results into groups of 5

Thread began 2/26/2011 10:58 am by phebberd116714 | Last modified 3/02/2011 9:39 am by Jason Byrnes | 1778 views | 13 replies |

phebberd116714

Splitting results into groups of 5

I would like to display the results of a record set in groups of 5.

Each group would be in a div container and each item in an unordered list.
Like this:

<div>
<!-- 1-5 -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
</div>
<!-- 6-10 -->
<div>
<ul>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
</ul>
</div>
<!-- 11-15 -->
<div>
<ul>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
</ul>
</div>

Can that be done using a repeating region behaviour. Is it even possible?

Any help would be greatly appreciated.

Sign in to reply to this post

CraigRBeta Tester

how many sets of 5 are you looking to produce ?

for three sets you could do this with 3 recordsets using the LIMIT clause to select the number of rows and the offset

ther may well be other ways

Sign in to reply to this post

phebberd116714

The number of sets would depend on how many items were in the database at any given time. So I don't think it can be done by different record sets.

But thanks for the reply.

Sign in to reply to this post

CraigRBeta Tester

depending on how your data is grouped, there is another option which could work for you, (with a single recordset)

take a look at this link and see if it works for you.

post_Create_nested_lists_from_a_recordset__PHP_-16720.html

Sign in to reply to this post

phebberd116714

Thanks Craig,
I took a look at the article but that won't work either. If there were say, 8 items under a date, then it would show 8 rather than splitting into groups of 5.

What I eventually want to achieve, is create a scrollable list of images (these would be related to another main image by type.) For instance, choosing a tile style would show that main image and underneath would be a scrollable list of similar tiles.

I found a jQuery scroller (index.html) that achieves the scrolling I like but it works by having the images in groups of 5 inside separate div containers.

So, any ideas?

Sign in to reply to this post

Jason ByrnesWebAssist

you would need to hand code this manually in the results set.


the basic gist of the code would use a counter that you increment inside of the loop, if it equals five start a new div:




something like:

<?php $count=1; ?>
<?php if($count==1) { ?>
<div>
<ul>
<?php } ?>
<?php do {
<li><?php echo $row_rsname['column']; ?></li>
<?php $count ++; ?>
<?php if($count==6) { ?>
<?php $count=1; ?>
</ul>
</div>
<?php } ?>
<?php } while ($row_rsname = mysql_fetch_assoc($rsname)); ?>


This is just the basic idea, you may need to adjust the code to get the specific results you are looking for.

Sign in to reply to this post

phebberd116714

Thanks Jason,

When I put in your code Dreamweaver was showing an error (attachment 1) and I got no results.

I added a closing tag after the <?php do (attachment 2) and that does split the results into blocks of 5.

But it is not adding the beginning div and ul tags for the subsequent sets of 5 and nothing except the li tags on a set less than 5.

The result:

<div>
<ul>
<li>image1</li>
<li>image2</li>
<li>image3</li>
<li>image4</li>
<li>image5</li>
</ul>
</div>
<li>image6</li>
<li>image7</li>
<li>image8</li>
<li>image9</li>
<li>image10</li>
</ul>
</div>
<li>image11</li>
<li>image12</li>
<li>image13</li>
<li>image14</li>
<li>image15</li>
</ul>
</div>
<li>image16</li>
<li>image17</li>

Can you point out where I am going wrong.

Thanks in advance.

Sign in to reply to this post

CraigRBeta Tester

try this instead...

<?php $count=1; ?>
<?php do { ?>
<?php if($count==1) { ?>
<div>
<ul>
<?php } ?>
<li><?php echo $row_rsname['column']; ?></li>
<?php $count ++; ?>
<?php if($count==6) { ?>
</ul>
</div>
<?php $count=1; ?>
<?php } ?>
<?php } while ($row_rsname = mysql_fetch_assoc($rsname)); ?>
Sign in to reply to this post

Jason ByrnesWebAssist

Thanks CraigR, that should fix it.

Sign in to reply to this post

CraigRBeta Tester

I love this forum, I'm always learning of better ways of doing things

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...