Re: Search MySQL db with PHP
- From: "Chris" <designerNOSPAM@xxxxxxxxxxxxxx>
- Date: Tue, 27 Jun 2006 12:35:11 -0700
Hi again,
Sorry Lorento - my brain typed Lorenzo :)
I got the search to work finally, however, I am having issues with getting
it to limit to a certain number of results per page. Then, of course,
there's getting the results to show in the content section of each page
since all pages have includes for the header, navigation, and footer
sections. Any guidelines on this would be appreciated.
Thanks,
Chris
"Chris" <designerNOSPAM@xxxxxxxxxxxxxx> wrote in message
news:e7rrlk$cm$1@xxxxxxxxxxxxxxxxxxx
Hi,
Thanks Lorenzo...Actually, that part I saw right after I posted and
changed it to keyword throughout as it is supposed to search 3 different
columns, but it still won't pass the value. I assigned a varible to it:
$keyword = $_POST['keyword']; I also separated the 2 pages, 1 for the
form, and 1 for the results because at one point the form was coming up
with 2 items listed below it without even inputting a search keyword.
It still won't work. I thought this would be so easy...
This is what I have now, and it just gives me another error: "You have an
error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near 'LIMIT 0, 25' at line 1".
I have looked at the MySQL manual/site and there is very little reference
to LIMIT, as well as researching PHP and Googling the error. I have some
familiarity with SQL Server, but MySQL has slightly different syntax -
such as not wanting to recognize alias column names in the WHERE clause.
Form page:
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>Simple Search Form:</p>
<form id="search" name="search1" method="post" action="dwmxsearch.php">
<label>Keywords:
<input name="keyword" type="text" size="30"/>
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
<input name="submitted" type="hidden" value="submitted" />
</form>
<p>
</p>
</body>
</html>
Results page (includes page generation code):
<?php include('../Connections/website.php'); ?>
<?php
$currentPage = $_SERVER['PHP_SELF'];
$keyword = $_POST['keyword'];
$maxRows_search = 25;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
$pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;
mysql_select_db($database_website, $website);
$query_search = "SELECT DISTINCT docURL as URL, docTitle as Title, docDesc
as Description, projCode as Project FROM docs, proj WHERE docs.projID =
proj.projID AND docURL LIKE "%$keyword%" OR docTitle LIKE "%$keyword%"'
OR docDesc LIKE "%$keyword%"";
$query_limit_search = sprintf("%s LIMIT %d, %d", $query_search,
$startRow_search, $maxRows_search);
$search = mysql_query($query_limit_search, $website) 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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>
<?php do { ?>
<a href="<?php echo $row_search['URL']; ?>"><?php echo
$row_search['Title']; ?></a> :<br />
<strong>Description:</strong> <?php echo $row_search['Description'];
?>, <strong>Project:</strong> <?php echo $row_search['Project']; ?><br />
<?php } while ($row_search = mysql_fetch_assoc($search)); ?>
</p>
<p>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?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 width="31%" align="center"><?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 width="23%" align="center"><?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 width="23%" align="center"><?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>
</p>
</body>
</html>
<?php
mysql_free_result($search);
?>
"lorento" <laurente1234@xxxxxxxxx> wrote in message
news:1151406437.726096.182120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Chris wrote:
I have tried assigning a variable to the textbox value, but thatIts because the keyword didn't pass to action page. Try like this :
doesn't work either.
<form id="search" name="search1" method="post" action="search.php">
<label>Keywords:
<input name="docDesc" type="text" size="30"/>
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
--
http://blog.deshot.com
http://www.deshot.com
.
- Follow-Ups:
- Re: Search MySQL db with PHP
- From: Chris
- Re: Search MySQL db with PHP
- References:
- Search MySQL db with PHP
- From: Chris
- Re: Search MySQL db with PHP
- From: lorento
- Re: Search MySQL db with PHP
- From: Chris
- Search MySQL db with PHP
- Prev by Date: Re: Search MySQL db with PHP
- Next by Date: Re: Convert $string to gibberish - how?
- Previous by thread: Re: Search MySQL db with PHP
- Next by thread: Re: Search MySQL db with PHP
- Index(es):
Relevant Pages
|