Re: Search MySQL db with PHP



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 that
doesn't work either.
Its because the keyword didn't pass to action page. Try like this :

<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





.



Relevant Pages

  • Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
    ... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ...
    (comp.lang.php)
  • Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
    ... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ...
    (comp.lang.php)
  • Re: com_dotnet
    ... And if MySQL isn't installed, the DLL won't load and phpinfowill show MySQL support isn't enabled. ... The MySQL interface is NOT compiled into PHP on the distributed Windows binaries - or you'd never be able to run PHP unless you had MySQL installed. ... *SOME* extensions are protocols, some are functional resources, and some are just type libraries. ... If you're going to compile the extension into PHP itself, the libraries must be available at compile time, and when you run PHP, or PHP won't load. ...
    (comp.lang.php)
  • Re Re: PHP 5.2.4 <= various mysql functions safemode & open_basedir bypass
    ... > various mysql functions safemode & open_basedir bypass ... PHP is currently very used because it's easy to use. ... Apache has directory restrictions. ... # if the mysql user has perms, ...
    (Bugtraq)
  • Re: question about playlist
    ... I have a dynamic playlist, playlist_1.asx, created by a php script from a ... the mysql table contain information about: ... movie near to the playing movie, and when change the movie, contextually ... Change the information in the *database* table, or in the HTML table? ...
    (microsoft.public.windowsmedia.server)