Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 07-19-2006, 01:40 PM 20 results at a time
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
Could someone get me started in the right direction here.

I have a database thats going to fetch all records from the database, for browsing. I dont want the database to get HUGE and display lie 2k results at a time so i wanted to do only 20 at a time and make a link for the next 20. How could i go about doing that?
The_Anomaly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-19-2006, 02:13 PM Re: 20 results at a time
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
Not really something that can be answered in a short time for a forum member. Try a google search for a pagination tutorial.
__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 07-19-2006, 02:52 PM Re: 20 results at a time
Junior Talker

Posts: 4
Trades: 0
Check out MySQL Limit, at Google.
L3PA is offline
Reply With Quote
View Public Profile
 
Old 07-19-2006, 06:35 PM Re: 20 results at a time
The_Anomaly's Avatar
Extreme Talker

Posts: 216
Location: Boston, Ma
Trades: 0
Thx for the links. i have everything pretty much working but its displaying everything not just 5 at a time as i am asking ( i said 20 but the db only has a limited amount of data right now). I cant seem to find whats wrong. when i click the 1,2,3 links the page in the address bar says it has changed but all fields are still the same. Wanna take a look

Code:
<?php 

    require_once('Connections/nwodb.php'); 
    @mysql_select_db("nwo") or die("ERROR--CAN'T CONNECT TO DB"); 
     


    $limit          = 5; 	               
    $query_Recordset1    = "SELECT * FROM person ORDER BY LastName ASC";     
    $result_count   = mysql_query($query_Recordset1);     
    $totalrows      = mysql_num_rows($result_count);
   

    if(empty($page))
	{ 
        	$page = 1; 
        } 
         

    $limitvalue = $page * $limit - ($limit);  
    //$query_Recordset1  = "SELECT * FROM person ORDER BY LastName ASC";         
    //$result = mysql_query($query) or die("Error: " . mysql_error());  
       
       $Recordset1 = mysql_query($query_Recordset1, $nwodb) or die(mysql_error());
       $row_Recordset1 = mysql_fetch_assoc($Recordset1);
       $totalRows_Recordset1 = mysql_num_rows($Recordset1); 
    if(mysql_num_rows($Recordset1) == 0)
	{ 
        echo("Nothing to Display!"); 
        } 

    $bgcolor = "#E0E0E0"; // light gray 

    echo("<table>"); 
    echo("<tr><td>");
    echo("Member_ID");
    echo("</td><td>");
    echo("Last Name");
    echo("</td><td>");
    echo("First Name");
    echo("</td></tr>");
     
    while($row_Recordset1 = mysql_fetch_array($Recordset1))
    { 
        if ($bgcolor == "#E0E0E0")
	   { 
            	$bgcolor = "#FFFFFF"; 
            }else
	      { 
                 $bgcolor = "#E0E0E0"; 
              } 
  	
    			echo("<tr bgcolor=".$bgcolor."><td width=\"20%\">");
    			echo ($row_Recordset1["Person_ID"]);
    			echo ("</td><td width=\"40%\">");       
    			echo($row_Recordset1["LastName"]);
           	        echo ("</td><td>");        
    			echo($row_Recordset1["FirstName"]); 
    			echo("</td></tr>"); 
    } 

    echo("</table>"); 
//shows the previous # entries link
    if($page != 1){  
        $pageprev = $page--;          
        echo("<a href=\"pagation.php=$pageprev\">PREV".$limit."</a> ");  
    	}else
          { 
        	echo("PREV ".$limit." "); 
    	  } 
//shows the number of pages that can be selected from
    $numofpages = $totalrows / $limit;      
    for($i = 1; $i <= $numofpages; $i++)
      { 
        if($i == $page)
          { 
            echo($i." "); 
           }else
             { 
                echo("<a href=\"pagation.php?page=$i\">$i</a> "); 
             } 
          } 

//shows the next # enties link
    if(($totalrows % $limit) != 0)
       { 
        if($i == $page){ 
            echo($i." "); 
        }else
          { 
            echo("<a href=\"pagation.php?page=$i\">$i</a> "); 
           } 
       } 

    if(($totalrows - ($limit * $page)) > 0){ 
        $pagenext = $page++;          
        echo("<a href=\"pagation.php?page=$pagenext\">NEXT ".$limit."</a>");  
    }else{ 
        echo("NEXT ".$limit);  
    } 
     
    mysql_free_result($Recordset1); 

?>
I know its sloppy right now :|

Last edited by The_Anomaly; 07-19-2006 at 07:00 PM..
The_Anomaly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to 20 results at a time
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13587 seconds with 12 queries