Splitting list within a page
Moderator: General Moderators
Splitting list within a page
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
- 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
- evilchris2003
- Forum Contributor
- Posts: 106
- Joined: Sun Nov 12, 2006 6:43 am
- Location: Derby, UK
Split the list - Sorted - after a fashion
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
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
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 toJayBird 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++; }
Code: Select all
$result = mysql_query($sql);Thanks a million
Ian