hisham
IS-IT--Management
- Nov 6, 2000
- 194
Am trying to run the following code from :
<?php
$page = $_REQUEST['page'];
$query = $_POST['query'];
// check to see if $page is set
if (!$page) {
$page = 1;
}
// Change $query to a request super global after the first page.
if($page > 1){
$query = $_REQUEST['query'];
}
//set up some limits
$limit = $page * 10;
$limit = $limit - 10;
//get the count from the database table
$sql_num = mysql_query("SELECT * FROM table WHERE column LIKE %query%"
$num = mysql_num_rows($sql_num);
// query your database for the final results
$sql_results = mysql_query("SELECT something FROM table WHERE column LIKE %query% LIMIT $limit,10"
if($num < 10){
$through = $num;
} else {
$through = $limit + 10;
}
if ($through > $num){
$through = $total;
}
if($page > 1){
$from = $limit +1;
} else {
$from = $limit;
}
if($from == 0){
$from = $from +1;
}
echo "Search Results<br><br>";
echo "<p align=\"right\">";
if ($page > 1) {
echo "<a
href=\"$PHP_SELF?query=$query&page=".($page -1)."\">Previous</a> ";
}
if (($num > 10) && (($limit + 10) < $num)) {
echo "<a href=\"$PHP_SELF?query=$query&page=".($page +1)."\">Next</a>";
}
// Build the list from the $sql query above and display results
while(list($results)=mysql_fetch_array($sql_results)){
echo "Results: $results";
}
if ($page > 1) {
echo "<a
href=\"$PHP_SELF?query=$query&page=".($page -1)."\">Previous</a> ";
}
if (($num > 10) && (($limit + 10) < $num)) {
echo "<a href=\"$PHP_SELF?query=$query&page=".($page +1)."\">Next</a>";
}
?>
It returns the first 10 records of 24, but when I click Next , this take me to
(the parameter query seems null) with only the world Previous and without any record.
<?php
$page = $_REQUEST['page'];
$query = $_POST['query'];
// check to see if $page is set
if (!$page) {
$page = 1;
}
// Change $query to a request super global after the first page.
if($page > 1){
$query = $_REQUEST['query'];
}
//set up some limits
$limit = $page * 10;
$limit = $limit - 10;
//get the count from the database table
$sql_num = mysql_query("SELECT * FROM table WHERE column LIKE %query%"
$num = mysql_num_rows($sql_num);
// query your database for the final results
$sql_results = mysql_query("SELECT something FROM table WHERE column LIKE %query% LIMIT $limit,10"
if($num < 10){
$through = $num;
} else {
$through = $limit + 10;
}
if ($through > $num){
$through = $total;
}
if($page > 1){
$from = $limit +1;
} else {
$from = $limit;
}
if($from == 0){
$from = $from +1;
}
echo "Search Results<br><br>";
echo "<p align=\"right\">";
if ($page > 1) {
echo "<a
href=\"$PHP_SELF?query=$query&page=".($page -1)."\">Previous</a> ";
}
if (($num > 10) && (($limit + 10) < $num)) {
echo "<a href=\"$PHP_SELF?query=$query&page=".($page +1)."\">Next</a>";
}
// Build the list from the $sql query above and display results
while(list($results)=mysql_fetch_array($sql_results)){
echo "Results: $results";
}
if ($page > 1) {
echo "<a
href=\"$PHP_SELF?query=$query&page=".($page -1)."\">Previous</a> ";
}
if (($num > 10) && (($limit + 10) < $num)) {
echo "<a href=\"$PHP_SELF?query=$query&page=".($page +1)."\">Next</a>";
}
?>
It returns the first 10 records of 24, but when I click Next , this take me to
(the parameter query seems null) with only the world Previous and without any record.