Jump to content

Help with search bar please !!!


andrew_biggart

Recommended Posts

Hey everyone i hope someone can help me i currently have added a search bar to my online auction site, when ever i search its working to an extent. It displays the selected categories no problem but brings up every item in the category, not just what i searched for. Im assuming this is because it is searching for each individual letter and not each word!

 

I have tried $search = addslashes($_POST['search']); but i think this just takes away the white space. How do i define each word???

 

Im usuing the following code to do the search!

 

The actuall search bar code is

 

<form name="shop_search" method="post" action="results.php">
<img alt="search" src="search.gif" width="77" height="17" /><input name="q" type="text" id="search" style="width: 288px" />              
<?php
include("config3.php");
//get subjects from database
$sql = "SELECT * FROM $tbl_name ORDER BY id;";
$result = mysql_query($sql);
?><select name="cat">
<?php

//show subjects
while($catrow = mysql_fetch_assoc($result))
{
echo "<option value='" . $catrow['id'] . "'>" . $catrow['cat'] . "</option>";
}
?>
</select>
<input name="Submit1" type="submit" value="Search Urbanwear" />
</form>

 

 

and the results page is as follows

 

	<?php
		include("config.php");	
		$search = addslashes($_POST['search']);
		$cat=($_POST['cat']);
		// Retrieve data from database 
		$sql="SELECT * FROM $tbl_name WHERE item_name LIKE '%" . $search . "%' AND category_id LIKE $cat ";
		$result=mysql_query($sql);

		// Start looping rows in mysql database.
		while($rows=mysql_fetch_array($result)){
?>

 

any help or a poin in the right direction would be appreciated !

 

Thanks in advance

Link to comment
Share on other sites

Eh, I'm not exactly sure what you're asking, but if your refering to how you can type in multiple keywords and look up that, you can just assign an explode function using someting like + or 'space' as a delimiter, and then run each of those through a query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.