Jump to content


Photo

paging problem with limited search results


  • Please log in to reply
3 replies to this topic

#1 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 31 May 2006 - 04:06 PM

I am having trouble with the paging of my search results, the first page of results shows up fine, and it shows the proper number of pages, but if I click on page 2 or more, it says that I have 0 pages of results. This is the script I have that runs the results of my search.

PHP:

<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b>DT_STRING</b></td>
<td width="100"><b>ACCOUNT</b></td>
<td width="30"><b>ACCOUNT_TYPE</b></td>
<td width="150"><b>CLIENT_ID</b></td>
<td width="150"><b>USER_ID</b></td>
</tr>
<tr>
<td>


<?php

mysql_connect("mysql","root","rootroot");
mysql_select_db("AUDITMED");
$num = $_GET['num'];
if(empty($num)){
$num = 1;
};
$limit = 100;
$start = ($num-1)*$limit;
if ($start == 0){
$start = 1;
}

$metode = $_REQUEST['metode'];
$search = $_REQUEST['search'];
$metode2 = $_REQUEST['metode2'];
$search2 = $_REQUEST['search2'];
$metode3 = $_REQUEST['metode3'];
$search3 = $_REQUEST['search3'];


$query = "SELECT * FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' AND $metode3 LIKE '%$search3%' ORDER by CLIENT_ID LIMIT $start, $limit";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)){
$variable1=$row["DT_STRING"];
$variable2=$row["ACCOUNT"];
$variable3=$row["ACCOUNT_TYPE"];
$variable4=$row["CLIENT_ID"];
$variable5=$row["USER_ID"];
//table layout for results

echo ("<tr>");
echo ("<td>$variable1</td>");
echo ("<td>$variable2</td>");
echo ("<td>$variable3</td>");
echo ("<td>$variable4</td>");
echo ("<td>$variable5</td>");
echo ("</tr>");
};
$totalpages = mysql_num_rows(mysql_query("SELECT * FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' AND $metode3 LIKE '%$search3%'"));

$totalpages = $totalpages / $limit;

if ($totalpages == round($totalpages,0)) {
$totalpages = round($totalpages,0) ;
}else {
$totalpages = round($totalpages,0) + 1;
}

$c = 0;
echo "<br>";
while($c<$totalpages){
$page = ++$c;
if($_GET['num']==$page){
echo "[$page] ";
}else{//else
echo "<a href=?num=$page>[$page] </a>";
}
}
echo "<br>".$totalpages." Pages in total.";
?>

</table>
</center>



What in the world am I missing?

#2 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 31 May 2006 - 05:22 PM

Are you including these variables in your URL qurey?

"<a href=?num=$page&...........>

$metode = $_REQUEST['metode'];
$search = $_REQUEST['search'];
$metode2 = $_REQUEST['metode2'];
$search2 = $_REQUEST['search2'];
$metode3 = $_REQUEST['metode3'];
$search3 = $_REQUEST['search3'];

Otherwise the sql query won't find any data.

NoGray.com


#3 ccutla

ccutla
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 31 May 2006 - 06:21 PM

I have not done that, but I am kind of new to this so I can't seem to get it to work properly when I add the variables into the url string this is the way I'm trying to do it, but it definitely isn't working right.

while($c<$totalpages){
$page = ++$c;
if($_GET['num']==$page){
echo "[$page] ";
}else{//else
echo "<a href=?num=$page&[
$metode = $_REQUEST['metode'];
$search = $_REQUEST['search'];
$metode2 = $_REQUEST['metode2'];
$search2 = $_REQUEST['search2'];
$metode3 = $_REQUEST['metode3'];
$search3 = $_REQUEST['search3'];
>[$page] </a>";
}
}
echo "<br>".$totalpages." Pages in total.";

#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 31 May 2006 - 06:54 PM

Sorry, I was just point to the variables. Here is how you should do it
echo "<a href=?num=$page&metode=$metode&search=$search&metode2=$metode2&search2=$search2&metode3=$metode3&search3=$search3>[$page] </a>";

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users