普通网友 2010-11-13 17:32
浏览 5
已采纳

PHP搜索脚本不会正确返回页面

Since no other topics uses the script I use, I need serious help. I am currently working on a work project and my search feature returns the first page correctly but when I click Next 10 it does absolutely nothing! Please note I removed some code but left useless comments in, though that wont affect the performance of the script! Here is my code but ofcourse I have filtered the username and password: <

<?php

  // Get the search variable from URL

  $var = @$_GET['q'] ;
  $error = $_GET['error'];
  $permnull = @$_GET['nullpermitted'] ;
  $AdminorSuper = "";
  $trimmed = trim($var); //trim whitespace from the stored variable


if(!$session->isSuperuser()){
 $AdminorSuper = "Admin";
}

else
{
 $AdminorSuper = "";
}
// rows to return
$limit=10; 

if($error=="errdel")
{
 echo "<p>Only Admins and Superusers may delete customers. </p>";
}
if($error=="errcret")
{
 echo "<p>Only Admins and Superusers may create customers. </p>";
}
// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("*FILTERED*","*FILTERED*","*FILTERED*"); //(host, username, password)


mysql_select_db("*FILTERED*") or die("Unable to select database"); 

// Build SQL Query  
$query = "select * from customer where Surname OR TitleName OR PostCode like \"%$trimmed%\"  
  order by Surname"; 

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);



if ($numrows == 0)
  {
  if($trimmed=="")
  {
  echo "No customers are in the database!";
  }
  else
  {
  echo "<h2>Results</h2>";
  echo "<p>Sorry! No Results were found for: &quot;" . $trimmed . "&quot;.</p>";
  }
  }

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
if($var=="")
{
 echo "<p>Viewing all Results</p>";
}
else
{
echo "<p>Results for: &quot;" . $var . "&quot;</p>";
}
// begin to show results set
echo "";
$count = 1 + $s ;

// now you can display the results returned
  echo '<table border="1">';
  echo "<tr><td><b>Surname</b></td><td><b>Title/Name</b></td><td><b>Email</b></td><td><b>Telephone</b></td><td><b>Edit</b></td><td><b>Del</b></td></tr>
";
  while ($row= mysql_fetch_array($result)) {
  $Surname = $row["Surname"];
  $Title = $row["TitleName"];
  $Email = $row["Email"];
  $Telephone = $row["Telephone"];
  $id = $row["id"];
  echo '<tr><td>' .$Surname.'</td><td>'.$Title.'</td><td>'.$Email.'</td><td>'.$Telephone.'</td><td>' . '<a href="updateCustomerForm' . $AdminorSuper. '.php?id='.$id.'">[EDIT]</a></td>'.'<td>'. '<a href="deleteCustomer.php?id='.$id.'">[x]</a></td>'. '</tr>';
  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }
echo "</table>";
// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";

?>
  • 写回答

2条回答 默认 最新

  • ds1379551 2010-11-13 17:43
    关注

    It seems that the code missing $s=$_GET['s'];

    Good Luck :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题