Splitting list within a page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ijyoung
Forum Newbie
Posts: 6
Joined: Wed Nov 15, 2006 7:22 am

Splitting list within a page

Post by ijyoung »

I want to be able to split a list within a page so that I can insert an instruction after every 10 results or so

- for example a #top link.
I have tried to customise a paging script but that limits the number of results per page.

Any thought on how that could be achieved?

Ian
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

What does your code look like now?

NB: Please read how to post code before doing so
ijyoung
Forum Newbie
Posts: 6
Joined: Wed Nov 15, 2006 7:22 am

Post by ijyoung »

Not sure the value of sending the code. It is a bog standard piece of php for paging results which works well enough for that.

I was looking for some code that would allow me to split the list but not paginate.

If you still want to see code then fair enough.

Where are posting guidelines?
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Post by evilchris2003 »

see the top of this section of the fourm

one of the Sticky posts
ijyoung
Forum Newbie
Posts: 6
Joined: Wed Nov 15, 2006 7:22 am

Post by ijyoung »

Ta.

Kinda obvious huh? :oops:

Ian
ijyoung
Forum Newbie
Posts: 6
Joined: Wed Nov 15, 2006 7:22 am

Split the list - Sorted - after a fashion

Post by ijyoung »

I have sorted the problem for now, albeit a bit inelegantly by using separate queries and limits as follows:

LIMIT 0,5
LIMIT 6,5
LIMIT 11,5
LIMIT 16,5
LIMIT 21,5 etc

Anyone have a suggestion how we could accomplish this so that no matter how many records were called it would limit them in the above sequence?

Ian
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Example (untested)

Code: Select all

$sql = "SELECT * FROM `yourTable`";

$result = mysql_query($result);

$counter = 1;

while($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo $line['someFieldName'];

    if(($counter % 5) == 0)
    {
        echo "back to top link here";
    }

    $counter++;
}
ijyoung
Forum Newbie
Posts: 6
Joined: Wed Nov 15, 2006 7:22 am

Post by ijyoung »

Thanks.

This looks great. I'll try tomorrow as I am out this evening.

Ian
ijyoung
Forum Newbie
Posts: 6
Joined: Wed Nov 15, 2006 7:22 am

Post by ijyoung »

JayBird wrote:Example (untested)

Code: Select all

$sql = "SELECT * FROM `yourTable`";

$result = mysql_query($result);

$counter = 1;

while($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo $line['someFieldName'];

    if(($counter % 5) == 0)
    {
        echo "back to top link here";
    }

    $counter++;
}
Brilliant. works a treat when you change line two to

Code: Select all

$result = mysql_query($sql);
But you knew that
Thanks a million

Ian
Post Reply