cvs: php-bugs-web / search.php
| From: | Jim Winstead | Date: | Mon, 24 Sep 2001 02:42:54 +0000 |
| Subject: | cvs: php-bugs-web / search.php | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-6644@lists.php.net to get a copy of this message | ||
jimw Sun Sep 23 22:42:54 2001 EDT
Modified files:
/php-bugs-web search.php
Log:
when a search_for is supplied and no order_by, use relevance for ordering, and get accurate count
of rows to display how many records were found
Index: php-bugs-web/search.php
diff -u php-bugs-web/search.php:1.1 php-bugs-web/search.php:1.2
--- php-bugs-web/search.php:1.1 Sun Sep 23 19:27:04 2001
+++ php-bugs-web/search.php Sun Sep 23 22:42:54 2001
@@ -25,7 +25,7 @@
$where_clause .= " AND status='Feedback' AND
TO_DAYS(NOW())-TO_DAYS(ts2)>60";
} elseif ($status == "Stale") {
$where_clause .= " AND status != 'Closed' AND status != 'Duplicate' AND
status != 'Bogus' AND TO_DAYS(NOW())-TO_DAYS(ts2) > 30";
- } elseif (isset($status) && $status != "All") {
+ } elseif ($status && $status != "All") {
$where_clause .= " AND status='$status'";
}
@@ -50,38 +50,45 @@
$query .= "$where_clause ";
- if (!$order_by) $order_by = "id";
- if (!$direction) $direction = "ASC";
-
- if ($reorder_by) {
- if ($order_by == $reorder_by) {
- $direction = $direction == "ASC" ? "DESC" : "ASC";
- }
- else {
- $direction = "ASC";
+ /* we avoid adding an order by clause if using the full text search */
+ if ($order_by || $reorder_by || !strlen($search_for)) {
+ if (!$order_by) $order_by = "id";
+ if (!$direction) $direction = "ASC";
+
+ if ($reorder_by) {
+ if ($order_by == $reorder_by) {
+ $direction = $direction == "ASC" ? "DESC" : "ASC";
+ }
+ else {
+ $direction = "ASC";
+ }
+ $order_by = $reorder_by;
}
- $order_by = $reorder_by;
- }
-
- $query .= " ORDER BY $order_by $direction";
+ $query .= " ORDER BY $order_by $direction";
+ }
if (!$begin) $begin = 0;
if (!isset($limit)) $limit = 30;
if($limit!='All') $query .= " LIMIT $begin,$limit";
- $res = @mysql_query($query);
+ $res = @mysql_query("SELECT COUNT(*) FROM bugdb $where_clause");
if (!$res) die(htmlspecialchars($query)."<br>".mysql_error());
+ $row = mysql_fetch_row($res);
- $rows = mysql_numrows($res);
- if (!$rows) {
+ $total_rows = $row[0];
+ if (!$total_rows) {
echo "<h2 class=\"error\">No bugs with the specified criteria were
found.</h2>";
}
else {
+ $res = @mysql_query($query);
+ if (!$res) die(htmlspecialchars($query)."<br>".mysql_error());
+ $rows = mysql_numrows($res);
+
$link = "$PHP_SELF?cmd=display&bug_type=" . urlencode ($bug_type) .
"&status=$status&search_for=".htmlspecialchars(stripslashes($search_for))."&php_os=".htmlspecialchars(stripslashes($php_os))."&bug_age=$bug_age&by=$by&order_by=$order_by&direction=$direction&phpver=$phpver&limit=$limit";
?>
<table align="center" border="0" cellspacing="2"
width="95%">
- <?php show_prev_next($begin,$rows,$link,$limit);?>
+ <?php show_prev_next($begin,$rows,$total_rows,$link,$limit);?>
<tr bgcolor="#aaaaaa">
<th><a href="<?php echo
$link;?>&reorder_by=id">ID#</a></th>
<?php if ($bug_type == "Any") {?>
@@ -113,7 +120,7 @@
echo "</tr>\n";
}
- show_prev_next($begin,$rows,$link,$limit);
+ show_prev_next($begin,$rows,$total_rows,$link,$limit);
?>
</table>
<?php
@@ -156,16 +163,23 @@
}
commonFooter();
-function show_prev_next($begin,$rows,$link,$limit) {
+function show_prev_next($begin,$rows,$total_rows,$link,$limit) {
if($limit=='All') return;
if ($begin == 0 && $rows < $limit) return;
echo "<tr bgcolor=\"#cccccc\"><td align=\"center\"
colspan=\"9\">";
echo '<table border="0" cellspacing="0" cellpadding="0"
width="100%"><tr>';
if ($begin > 0) {
- echo "<td align=\"left\"><a
href=\"$link&begin=",max(0,$begin-$limit),"\">« Show
Previous $limit Entries</a></td>";
- }
- if ($rows >= $limit) {
- echo "<td align=\"right\"><a
href=\"$link&begin=",$begin+$limit,"\">Show Next $limit Entries
»</a></td>";
+ echo "<td align=\"left\" width=\"33%\"><a
href=\"$link&begin=",max(0,$begin-$limit),"\">« Show
Previous $limit Entries</a></td>";
}
+ else {
+ echo "<td width=\"33%\"> </td>";
+ }
+ echo "<td align=\"center\" width=\"34%\">Showing
",$begin+1,"-", $begin+1+$rows, " of $total_rows</td>";
+ if ($begin+$rows < $total_rows) {
+ echo "<td align=\"right\" width=\"33%\"><a
href=\"$link&begin=",$begin+$limit,"\">Show Next $limit Entries
»</a></td>";
+ }
+ else {
+ echo "<td width=\"33%\"> </td>";
+ }
echo "</tr></table></td></tr>";
}