|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Need help, creating multiple pages.
I have a news system, that gets 5 rows of data.
I need to make it where it has pages, and gets 5 rows of data on each page, if available. Heres some of my code: Code:
<?php
$query = 'SELECT * FROM gdl_news ORDER BY date_entered DESC limit 0,5';
if ($r = mysql_query ($query)) {
while($row = mysql_fetch_array ($r)) {
print "<p><b>{$row['subject']}</b> - {$row['date_entered']}<br />
{$row['news_entry']}<br /></p><hr />\n";
}
}else{
die('Could not retrieve data because:<b>' . mysql_error() . '</b>.');
}
?>
|
|
#2
|
|||
|
|||
|
In the LIMIT 0,5 , assign a var to 0 somrhting like $temp_var=0.
Now, when you want to change page pass the new $temp_var example <a href="mypage.php?p=5">Next</a> So in the new page the $temp_var would be 5 and your LIMIT 0,5 would become LIMIT 5,5 Finnaly you would get something like : <? if ($p!="") { $temp_var = $p; } else { $temp_var=0; } // execute your query here ?> |
|
#3
|
|||
|
|||
|
Quote:
Suggestion: make yout LIMI dynamic -> LIMIT $var,5 above your query write something like: PHP Code:
Now in your query write LIMIT $var,5 instead of 0,5 and your link would be something like: mypage.php?p=5 In this way, when you click on the link the $var becomes 5 and the LIMIT 0,5 becomes LIMIT5,5 Ideally you need to read some tutorials on pagination |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Need help, creating multiple pages. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|