Log in

View Full Version : How can i add search to dreamwever pagination



mike2098
12-23-2009, 02:19 PM
Hi I have created a page that paginates the results of a database how can I add my search box to the code so it only displays the results paginated

thanks


<?php require_once('Connections/search_site.php');

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_search = 10;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
$pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;

mysql_select_db($database_search_site, $search_site);
$query_search = "SELECT * FROM articles ORDER BY id ASC";
$query_limit_search = sprintf("%s LIMIT %d, %d", $query_search, $startRow_search, $maxRows_search);
$search = mysql_query($query_limit_search, $search_site) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);

if (isset($_GET['totalRows_search'])) {
$totalRows_search = $_GET['totalRows_search'];
} else {
$all_search = mysql_query($query_search);
$totalRows_search = mysql_num_rows($all_search);
}
$totalPages_search = ceil($totalRows_search/$maxRows_search)-1;

$queryString_search = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_search") == false &&
stristr($param, "totalRows_search") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_search = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_search = sprintf("&totalRows_search=%d%s", $totalRows_search, $queryString_search);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

//include("header.php");
include("conf.php");
?>

<div id="container2">
<div id="content"><br />
<form action="search.php" method="GET">
Search Site:
<input type="text" name="q" />
<input type="submit" name="search class="submit-btn" src="btn.gif" alt="submit" title="submit" />
</form>
<br />
<br />


<table border="0">
<tr>
<td><?php if ($pageNum_search > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_search=%d%s", $currentPage, 0, $queryString_search); ?>">First</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_search > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_search=%d%s", $currentPage, max(0, $pageNum_search - 1), $queryString_search); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_search < $totalPages_search) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_search=%d%s", $currentPage, min($totalPages_search, $pageNum_search + 1), $queryString_search); ?>">Next</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_search < $totalPages_search) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_search=%d%s", $currentPage, $totalPages_search, $queryString_search); ?>">Last</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
<table border="1" cellpadding="3" cellspacing="3">
<tr>
<td>id</td>
<td>category</td>
<td>title</td>
<td>body</td>
<td>rate</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_search['id']; ?></td>
<td><?php echo $row_search['category']; ?></td>
<td><?php echo $row_search['title']; ?></td>
<td><?php echo $row_search['body']; ?></td>
<td><?php echo $row_search['rate']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_assoc($search)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($search);
?>