|
Posted by Chris on 06/26/06 21:13
Hi,
I have 3 tables in a MySQL db that I want to search with PHP. I have seen
several basic db search code examples, and have tried most. They all seem
to have different approaches - some are easy to follow, some are extremely
complicated to follow. Unfortunately, every one I have tried doesn't seem
to want to give results, it is as if the value of the textbox where the user
inputs the keyword(s) never gets defined as a variable. I have tried
assigning a variable to the textbox value, but that doesn't work either. I
have coded some of these examples from scratch, as well as creating one in
Dreamweaver. Below is the current DW code (which is about the simplest
believe it or not - I did remove the coding for limiting the number of
results per page to keep the stuff below to a minimum). It's also returning
a couple of records without any keywords begin input. I think I'm just at
burnout stage and can't even read the code anymore....much less edit
it....can someone tell me what I'm overlooking?
Thanks,
Chris
<?php include('../Connections/website.php'); ?>
<?php
$colname_simplesearch = "-1";
if (isset($_POST['docDesc'])) {
$colname_simplesearch = (get_magic_quotes_gpc()) ? $_POST['docDesc'] :
addslashes($_POST['docDesc']);
}
mysql_select_db($database_website, $website);
$query_simplesearch = sprintf("SELECT docURL, docTitle, docDesc FROM docs
WHERE docDesc LIKE '%%%s%%'", $colname_simplesearch);
$simplesearch = mysql_query($query_simplesearch, $website) or
die(mysql_error());
$row_simplesearch = mysql_fetch_assoc($simplesearch);
$totalRows_simplesearch = mysql_num_rows($simplesearch);
?>
..........
<body>
<p>Simple Search Form:</p>
<form id="search" name="search1" method="post" action="search.php">
<label>Keywords:
<input name="keyword" type="text" size="30"/>
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</form>
<p>
<?php do { ?>
<a href="<?php echo $row_simplesearch['docURL'];
?>">{simplesearch.docTitle}</a> : <?php echo $row_simplesearch['docDesc'];
?><br />
<?php } while ($row_simplesearch = mysql_fetch_assoc($simplesearch));
?></p>
</body>
</html>
<?php
mysql_free_result($simplesearch);
?>
Navigation:
[Reply to this message]
|