hi,
i am going to create a pagination in php in basis of retrieving the data
from the database. i tried to combine two different query result in same pagination but i don't get the desired result.

here is my code:-

<?php
include 'mysql-connect.php';

$qs=$_REQUEST["qs"];
$d=$qs;
$a=$d;

if (isset($_GET['a']))
 {
	 $a=$_GET['a'];
	
 }



 if (!isset($_REQUEST['qs']))
 {
	 $_REQUEST['qs']= $a;
	 $mak=$_REQUEST['qs'];

	 
 }
?>
<input type="hidden" name="qs" value="<?php echo $_REQUEST['qs']; ?>">
<?php

$token = strtok($qs, " "); //create token from the input data like 'database management' 
$st1="";
$val=array();
$i=0;
while ($token !== false)
  {
   $st1=$st1." ".$token;
   $val[$i]=$st1;    //take token into the array
  $token = strtok(" "); 
  $i++;
  }
 $val2=array();
$val2=array_reverse($val);  //make reverse of token array
$choice1=$val2[0];
$choice2=$val2[1];
$choice1=ltrim($choice1); //main entry data like 'database management'
$choice2=ltrim($choice2); //token data like 'database'

   // how many rows to show per page
$rowsPerPage = 20;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$order = " SELECT * FROM `books_data_master` WHERE  CONCAT(Title_Short,Title_Long ,Authors_Name,Publisher ) LIKE '%$choice1%' ".
	" LIMIT $offset, $rowsPerPage";
	 $query1 = mysql_query($order);

while($detail1=mysql_fetch_row($query1))
{
 echo("<tr><td>$detail1[1]</td>&nbsp;&nbsp;&nbsp;<td>$detail1[2]</td>&nbsp;&nbsp;&nbsp;<td>$detail1[3]</td>&nbsp;&nbsp;&nbsp;</tr>");
 echo ("<a href=\"more_info_used.php?id=$detail1[1]\">More Info</a>"); //fetch record for 'database management' entry
 echo "<br><br>";
}
$order1 = " SELECT * FROM `books_data_master` WHERE  CONCAT(Title_Short,Title_Long ,Authors_Name,Publisher ) LIKE '%$choice2%' ".
	" LIMIT $offset, $rowsPerPage";
	 $query2 = mysql_query($order1);
while($detail2=mysql_fetch_row($query2))
{
 echo("<tr><td>$detail2[1]</td>&nbsp;&nbsp;&nbsp;<td>$detail2[2]</td>&nbsp;&nbsp;&nbsp;<td>$detail2[3]</td>&nbsp;&nbsp;&nbsp;</tr>");
 echo ("<a href=\"more_info_used.php?id=$detail2[1]\">More Info</a>"); //fetch record for 'database' entry
 echo "<br><br>";
}
$query1   = "SELECT COUNT(*) AS numrows FROM `books_data_master` WHERE  CONCAT(Title_Short,Title_Long ,Authors_Name,Publisher ) LIKE '%$choice1%'";
$result1  = mysql_query($query1) or die('Error, query failed');
$row1     = mysql_fetch_array($result1, MYSQL_ASSOC);
$numrows = $row1['numrows']; //num of rows for 'database management' entry


$query2   = "SELECT COUNT(*) AS numrows FROM `books_data_master` WHERE  CONCAT(Title_Short,Title_Long ,Authors_Name,Publisher ) LIKE '%$choice2%'";
$result2  = mysql_query($query2) or die('Error, query failed');
$row2     = mysql_fetch_array($result2, MYSQL_ASSOC);
$numrows1 = $row2['numrows']; //num of rows for 'database' entry


// how many pages we have when using paging?
$maxPage = ceil(($numrows+$numrows1)/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];


if ($pageNum > 1)        
{
   $page  = $pageNum - 1;
   $prev  = " <a href=\"$self?page=$page&qs=$choice1\">[Prev]</a> ";

   $first = " <a href=\"$self?page=1&qs=$choice1\">[First Page]</a> ";
}
else
{
   $prev  = '&nbsp;'; // we're on page one, don't print previous link
   $first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)

{
   $page = $pageNum + 1;
   $next = " <a href=\"$self?page=$page&qs=$choice1\">[Next]</a> ";

   $last = " <a href=\"$self?page=$maxPage&qs=$choice1\">[Last Page]</a> ";
}
else
{
   $next = '&nbsp;'; // we're on the last page, don't print next link
   $last = '&nbsp;'; // nor the last page link
}


echo  .$first . $prev .
" Showing page $pageNum of $maxPage pages " . $next . $last;
}

the problem is the pagination does not get the output for the
two diff query's. i think i do some mistake.
can any one help me what is the problem. plz help me.it is urgent for me.

Merge both those two arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.