Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>";
    ?>

  • #2
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    use LIMIT

    $query = "SELECT * FROM defaulter WHERE NamaMajikan IS NOT NULL LIMIT 50";

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  • #4
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Then just use pagination and limit the number of pages.

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 1 Time in 1 Post
    And here you have a great example of how to do pagination:
    PHP5 Pagination

  • #6
    12k
    12k is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    0
    Thanked 6 Times in 6 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •