Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-14-2012, 10:10 AM   PM User | #1
dunhillx69
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dunhillx69 is an unknown quantity at this point
Exclamation Limit MySQL result per page

Hi... I need some help over here... attached is my coding that will display all the result in a single page. I need to limit the result let say to 50 results per page. Anybody can help me out here? Million thanks in advance...

Code:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("dbase") or die(mysql_error());

// Get all the data from the "defaulter" table
$result = mysql_query("SELECT * FROM `defaulter` WHERE `NamaMajikan` IS NOT NULL") 
or die(mysql_error());  

echo "<center>&nbsp;<br>";
echo "<table border='1' cellspacing='1' cellpadding='0'>";
echo "<tr> <th rowspan='2'>&nbsp;Kod Majikan&nbsp;</th> <th rowspan='2'>Nama Majikan</th> <th colspan='5'>Bilangan Bulanan</th> <th colspan='5'>Anggaran Amaun Tertunggak</th> <th rowspan='2'>&nbsp;Jumlah Besar&nbsp;</th></tr>";
echo "<tr><th>&nbsp;2007&nbsp;</th> <th>&nbsp;2008&nbsp;</th> <th>&nbsp;2009&nbsp;</th> <th>&nbsp;2010&nbsp;</th> <th>&nbsp;2011&nbsp;</th><th>&nbsp;2007&nbsp;</th> <th>&nbsp;2008&nbsp;</th> <th>&nbsp;2009&nbsp;</th> <th>&nbsp;2010</th> <th>&nbsp;2011&nbsp;</th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>&nbsp;"; 
	echo $row['KodMajikan'];
	echo "</td><td>&nbsp;"; 
	echo $row['NamaMajikan'];
	echo "</td><td align='center'>"; 
	echo $row['Bil2007'];
	echo "</td><td align='center'>"; 
	echo $row['Bil2008'];
	echo "</td><td align='center'>"; 
	echo $row['Bil2009'];
	echo "</td><td align='center'>"; 
	echo $row['Bil2010'];
	echo "</td><td align='center'>"; 
	echo $row['Bil2011'];
	echo "</td><td align='center'>"; 
	echo $row['Amt2007'];
	echo "</td><td align='center'>"; 
	echo $row['Amt2008'];
	echo "</td><td align='center'>"; 
	echo $row['Amt2009'];
	echo "</td><td align='center'>"; 
	echo $row['Amt2010'];
	echo "</td><td align='center'>"; 
	echo $row['Amt2011'];
	echo "</td><td align='center'>"; 
	echo $row['JumlahBesar'];
	echo "</td></tr>"; 
	
} 

echo "</table></center>";
?>
dunhillx69 is offline   Reply With Quote
Old 01-14-2012, 10:47 AM   PM User | #2
Kekke
New Coder

 
Join Date: Jan 2012
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Kekke is an unknown quantity at this point
use LIMIT

$query = "SELECT * FROM defaulter WHERE NamaMajikan IS NOT NULL LIMIT 50";
Kekke is offline   Reply With Quote
Old 01-14-2012, 10:52 AM   PM User | #3
dunhillx69
New to the CF scene

 
Join Date: Jan 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
dunhillx69 is an unknown quantity at this point
thanks for your reply mate... but to my understanding, that will only show 50 results, am i right...

my concern is let say it will show 300 results, it will display 50 results in first page and another 50 results in all other page... that means all together will be 6 pages

dunhillx69 is offline   Reply With Quote
Old 01-14-2012, 11:09 AM   PM User | #4
melloorr
Regular Coder

 
Join Date: Dec 2011
Location: NW England
Posts: 194
Thanks: 8
Thanked 15 Times in 15 Posts
melloorr is an unknown quantity at this point
Then just use pagination and limit the number of pages.
melloorr is offline   Reply With Quote
Old 01-14-2012, 11:26 AM   PM User | #5
Kekke
New Coder

 
Join Date: Jan 2012
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Kekke is an unknown quantity at this point
And here you have a great example of how to do pagination:
http://www.codingforums.com/showthread.php?t=151398
Kekke is offline   Reply With Quote
Old 01-15-2012, 03:11 AM   PM User | #6
12k
New Coder

 
Join Date: Jan 2012
Posts: 29
Thanks: 0
Thanked 6 Times in 6 Posts
12k is an unknown quantity at this point
Its pretty simple.

In your query:
SELECT * FROM `blah` LIMIT Start, Amount

Start = the number of rows where to start (typically page id * amount)

Amount = How many results u want displayed. Typically 10
12k is offline   Reply With Quote
Reply

Bookmarks

Tags
mysql, page, php, result

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:59 PM.


Advertisement
Log in to turn off these ads.