RE: [PHP] outputting db content

From: Date: Wed, 19 Dec 2001 15:37:30 +0000
Subject: RE: [PHP] outputting db content
Groups: php.general 
Request: Send a blank email to php-general+get-78216@lists.php.net to get a copy of this message
> Does anyone have a quick example of how you would show X > numbers of database records at a time from a query? (you > know, list 25 of 400 records with next/previous navigation)... I've used this code snippet and lots of projects and it seems to work pretty well. Would appreciate advice on how to make it more efficient. -schnippy ################################################################ // set number of records to display per screen $page_limit=15; // get a quick count of all available records $query = "select * from records"; $result = mysql_query($query); $num_records = mysql_num_rows($row_count_result); // construct the navigation string $nav_string = ""; if (!$min) { $min="1"; } if (!($min=="1")) { $pmin=$min-$page_limit; $nav_string .= "<a href='index.php?min=$pmin'>Previous $page_limit Records</a> -- "; } if ($x>$min+$page_limit) { $nmin=$min+$page_limit; $nav_string .= "<a href='index.php?min=$nmin'>Next $page_limit Records</a> -- "; $max = $nmin; } else { $max = $x; } // set the 'real' values for display and mysql $rmax = $max-1; $rmin = $min-1; $nav_string .= " Viewing records <b>$min</b> through <b>$max</b>"; $nav_string .= " -- There are $x records for this query<br>"; print $nav_string; // now select the range of records you want $query .="select * from records LIMIT $rmin,$page_limit"; $result = mysql_query($query); //display them or whatever ################################################################

« previous php.general (#78216) next »