SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old April 15th, 2005, 03:38 PM
Skynt Skynt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 Skynt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 29 sec
Reputation Power: 0
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>.');
   }
   
?>
 

Reply With Quote
  #2  
Old May 29th, 2005, 11:19 AM
kzar kzar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 6 kzar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 30 sec
Reputation Power: 0
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

?>

Reply With Quote
  #3  
Old May 29th, 2005, 11:23 AM
kzar kzar is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 6 kzar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by Skynt
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>.');
}
 
?>


Suggestion: make yout LIMI dynamic -> LIMIT $var,5
above your query write something like:
PHP Code:
<?
if ($p!="")
{
$var $p;
}
else
{
$var=0;
}
?>

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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Need help, creating multiple pages.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway