Aeron
10-13-2009, 11:08 AM
Hi guys,
I'm new here and I have a problem that I would really appreciate some help with.
What I need to to is pull some data from a mySQL database using the following code:
$sql = 'SELECT * FROM link_blog ORDER BY id DESC LIMIT 25';
$query = @mysql_query($sql);
I then need to be able to echo out 5 results, then break for some HTML code, and be able to break back into PHP and echo out the next 5 results in the array, and so on.
I normally use a while loop to return my values, but I need to be able to limit it to the first 5 results in the array, and then come back into PHP and pick up where I left off with the next set of 5 results in the array, and repeat.
To give you a code example of what I'm looking to do:
<?
//echo the first 5 results (needs counting or limiting code added)
while($array = mysql_fetch_array($query)){
echo'<a href="' . $array['url'] . '">' . $array['title'] . '</a>';
}
?>
//some html code
<?
//echo the next 5 results (needs counting or limiting code added)
while($array = mysql_fetch_array($query)){
echo'<a href="' . $array['url'] . '">' . $array['title'] . '</a>';
}
?>
//more html code. This needs to be repeated a number of times, which the pointer in the array moving back 5 each time.
If anyone knows how to easily do this, even if it's through a clumsy method like numerous mySQL queries, I'd be very appreciative.
Thanks for your help.
I'm new here and I have a problem that I would really appreciate some help with.
What I need to to is pull some data from a mySQL database using the following code:
$sql = 'SELECT * FROM link_blog ORDER BY id DESC LIMIT 25';
$query = @mysql_query($sql);
I then need to be able to echo out 5 results, then break for some HTML code, and be able to break back into PHP and echo out the next 5 results in the array, and so on.
I normally use a while loop to return my values, but I need to be able to limit it to the first 5 results in the array, and then come back into PHP and pick up where I left off with the next set of 5 results in the array, and repeat.
To give you a code example of what I'm looking to do:
<?
//echo the first 5 results (needs counting or limiting code added)
while($array = mysql_fetch_array($query)){
echo'<a href="' . $array['url'] . '">' . $array['title'] . '</a>';
}
?>
//some html code
<?
//echo the next 5 results (needs counting or limiting code added)
while($array = mysql_fetch_array($query)){
echo'<a href="' . $array['url'] . '">' . $array['title'] . '</a>';
}
?>
//more html code. This needs to be repeated a number of times, which the pointer in the array moving back 5 each time.
If anyone knows how to easily do this, even if it's through a clumsy method like numerous mySQL queries, I'd be very appreciative.
Thanks for your help.
