dongyi1524 2013-04-13 13:52
浏览 14

基于标准的分类搜索结果

This will be my first time to use a criteria-based search with pagination togather.

I want to paginat my search query results and be able to go to next and previous pages of my search results based on the search criteria. For now the pagination returns all records from the table. I have tried to include one search term in the URL link for NEXT and PREVIOUS buttons but still when I click the button I next page load all the records from the MySQL table. The search term (e.g. gallery.php?cmaterial=$cmaterial) appears in the URL only when I click NEXT and not on the current page. Even then the search results do not match the search term.

I tried to learn from previous posts on this topic but I am not sure were I am going wrong.

Here is my code:

<?php

$s=$_GET['s'];

// rows to return
$limit=12;

// check for a search parameter
//if (!isset($var))
//  {
//  echo "<p>We dont seem to have a search parameter!</p>";
//  exit;
//  }

$ctitle = mysql_real_escape_string($_POST['ctitle']);
$csubject = mysql_real_escape_string($_POST['csubject']);
$creference = mysql_real_escape_string($_POST['creference']);
$cat_id = ($_POST['cat_id']);
$cmaterial = mysql_real_escape_string($_POST['cmaterial']);
$ctechnic = mysql_real_escape_string($_POST['ctechnic']);
$cartist = mysql_real_escape_string($_POST['cartist']);
$csource = mysql_real_escape_string($_POST['csource']);
$stolen = mysql_real_escape_string($_POST['stolen']);

$sql = "SELECT * FROM collections WHERE c_id>0 AND `ctitle` LIKE '%".$ctitle."%' AND `csubject` LIKE '%".$csubject."%' AND `creference` LIKE '%".$creference."%' AND `cat_id` LIKE '%".$cat_id."%' AND `cmaterial` LIKE '%".$cmaterial."%' AND `ctechnic` LIKE '%".$ctechnic."%' AND `cartist` LIKE '%".$cartist."%' AND `csource` LIKE '%".$csource."%'  ORDER BY c_id ASC";

$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);

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

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

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

$count = 1 + $s ;

while ($row = mysql_fetch_assoc($sql_result)) {
    $c_id=$row['c_id'];
?>

..............................................HTML RESULT TABLE ...................................................

<?php
$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&cmaterial=$cmaterial\">&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&cmaterial=$cmaterial\">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>";

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c