PHP 搜索脚本无法正确返回页面

标签 php mysql database search

由于没有其他主题使用我使用的脚本,因此我需要认真的帮助。我目前正在处理一个工作项目,我的搜索功能正确返回第一页,但当我单击“下一步 10”时,它完全没有任何反应! 请注意,我删除了一些代码,但留下了无用的注释,尽管这不会影响脚本的性能! 这是我的代码,但我当然已经过滤了用户名和密码: <

<?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>\n";
  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>";

?>

最佳答案

代码似乎缺少$s=$_GET['s'];

祝你好运:)

关于PHP 搜索脚本无法正确返回页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4173791/

相关文章:

ruby - 二级数组排序,其中一个二级数​​组成员始终在顶部

php - 使用 javascript 重置表单将不起作用

php - MySQL 选择总和然后两个分组

php - 正则表达式删除字符串中三个或更少字符单词的第一个字符

php - Zend Framework 1.10 中自定义函数的放置位置

javascript - 数字插入数据库,但不插入字符或数字/字符

MYSQL - 仅当两个表都有条目时才显示结果

php - Mysql权限更新错误。

java - 带条件(真或某些原因导致 NPE)的 Hibernate 选择列表不返回任何结果

php - 特定时间自动从数据库中删除行