- Oct 21, 2003
- 99
- 0
- 0
I've got a bunch of articles in my DB and I want to be able to search them for terms using the AND or OR operand depending on a radio button. Right now im working on just getting the AND part of things working and here's what i've got:
The query sent in is in the text box named "query" (duh)... My connection to MySQL server is done in an external file and the DB is selected... everytime I try to search the DB nothing is returned although there are articles in there that should be returned...
$query_words[] = split(" ", $query); //put each word in a seperate element
$query_words2 = join($query_words, "%"); //insert wildcards into the query
$query = "%$query_words2%"; // put wildcards before and after first/last words
$sql = "SELECT id, title, author, section, LEFT(body, 47) as summary FROM articles WHERE BODY LIKE '$QUERY'";
$result = mysql_query($sql); //send the query
while ($row = mysql_fetch_row($result)) //print out each result in it's own table...
{
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="summarytitle">
<tr>
<td bgcolor="#DEDFCE" class="underline"><font size="2" face="Tahoma">» <a href="<?=$row[3]?>.php?i=<?=$row[0]?>"><?=$row[1]?> by <?=$row[2]?></a>
<?=$row[4]?></font></td>
</tr>
</table>
<?php
<?php
}
mysql_free_result($result); //clean it up
?>
Sorry that this post is kinda long... Thanx for any help provided...
The query sent in is in the text box named "query" (duh)... My connection to MySQL server is done in an external file and the DB is selected... everytime I try to search the DB nothing is returned although there are articles in there that should be returned...
$query_words[] = split(" ", $query); //put each word in a seperate element
$query_words2 = join($query_words, "%"); //insert wildcards into the query
$query = "%$query_words2%"; // put wildcards before and after first/last words
$sql = "SELECT id, title, author, section, LEFT(body, 47) as summary FROM articles WHERE BODY LIKE '$QUERY'";
$result = mysql_query($sql); //send the query
while ($row = mysql_fetch_row($result)) //print out each result in it's own table...
{
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="summarytitle">
<tr>
<td bgcolor="#DEDFCE" class="underline"><font size="2" face="Tahoma">» <a href="<?=$row[3]?>.php?i=<?=$row[0]?>"><?=$row[1]?> by <?=$row[2]?></a>
<?=$row[4]?></font></td>
</tr>
</table>
<?php
<?php
}
mysql_free_result($result); //clean it up
?>
Sorry that this post is kinda long... Thanx for any help provided...