Page 1 of 1
Splitting list within a page
Posted: Wed Nov 15, 2006 7:28 am
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
Posted: Wed Nov 15, 2006 8:09 am
by JayBird
What does your code look like now?
NB: Please read how to post code before doing so
Posted: Wed Nov 15, 2006 8:20 am
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?
Posted: Wed Nov 15, 2006 8:29 am
by evilchris2003
see the top of this section of the fourm
one of the Sticky posts
Posted: Wed Nov 15, 2006 8:36 am
by ijyoung
Ta.
Kinda obvious huh?
Ian
Split the list - Sorted - after a fashion
Posted: Wed Nov 15, 2006 9:52 am
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
Posted: Wed Nov 15, 2006 10:08 am
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++;
}
Posted: Wed Nov 15, 2006 10:55 am
by ijyoung
Thanks.
This looks great. I'll try tomorrow as I am out this evening.
Ian
Posted: Wed Nov 15, 2006 4:58 pm
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
But you knew that
Thanks a million
Ian