Re: Limit items per page like in Altavista.

From: Date: Thu, 31 Aug 2000 05:23:54 +0000
Subject: Re: Limit items per page like in Altavista.
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-14523@lists.php.net to get a copy of this message
I had the same question several months ago and someone sent me this code, so I'll pass it along....you will need to make the adjustments that fit your needs. ken // $conn is the link identifier to the MySQL server if( !isset($row) || $row == "" ) $row = 0; // number of the first row to show if( $row < 0 ) $row = 0; if( !isset($rxp) || $rxp == "" ) $rxp = 10; // rows to shwo in each page $sql = "SELECT * FROM <table_name>"; $result = mysql_query($sql, $conn); $numrows = mysql_num_rows($result); $numpages = floor( ($numrows - 1) / $rxp + 1 ); // now you know how many records you have and the number of // pages you'll need to show them $sql .= " LIMIT $row, $rxp"; $result = mysql_query($sql, $conn); // so the query gives you only $rxp records // every time you perform it .... now you show your records .... // Now put a link to the previous and next pages... echo "<a href=\"$PHP_SELF?row=".($row-$rxp)."&rxp=$rxp\">". "<<< Prev</a>"; echo "<a href=\"$PHP_SELF?row=".($row+$rxp)."&rxp=$rxp\">". "Next >>></a>"; Maxim Maletsky wrote: > > Hi! > > One of my script is getting data from mySQL database and then lists it all

« previous php.general (#14523) next »