Need Search Script Help Using PHP & MySQL

JesterJoker

Regular Member
Joined
Jan 13, 2008
Messages
238
Reaction score
28
So I have this page im pushing variables to. but need to output my search to the page.

heres what im working with.

this page is main.php


HTML:
<html>
<body>


<center>

<br>
<br>
<img src="Header/logo_big.png">

<div id="search">
					<div id="search_1" ></div>
					<div id="search_2" >
			
						<form action="http://mysite.com/store/search.php " method="POST" name="searchForm" style="margin:5px" enctype="multipart/form-data" >
			
							<select name="cat_id" style=" margin-left:10px; width:150px;">
							
								<option value="1">MySite.com</option>
		<option value="2">Action & Adventure</option>
		<option value="3">Animation</option>
		<option value="4">Comedy</option>
		<option value="5">Documentary</option>
		<option value="6">Drama</option>

		<option value="7">Horror</option>
		<option value="8">Kids & Family</option>
		<option value="9">Military & War</option>
		<option value="10">Music Video & Concerts</option>
		<option value="11">Musicals & Performing Arts</option>
		<option value="12">Mystery & Suspense</option>

		<option value="13">Science Fiction & Fantasy</option>
		<option value="14">Special Interests</option>
		<option value="15">Television</option>
		<option value="16">Westerns</option>
		<option value="17">Adult</option>
		<option value="18">Gay and Lesbian</option>
							
							</select>
			
							<input name="search_text" type="text"  style="margin-left:10px; width:260px;" />
			
							<input name="button" type="submit" value="Search" style="margin-left:10px; padding-bottom:2px;  background:url(http://<?=$_SERVER['HTTP_HOST']?>/store/Header/Untitled-2_r2_c12.png) no-repeat; width:58px; height:20px; border:none; color:#FFFFFF;  "/>
						</form>
			
					</div>
		
					<div id="search_3" ></div>
		
		
				</div>
		
			</div>

		</div>

</center>
		
		</body>
		</html>


so I need to develop the search.php page ..
and use the variables from the drop down menu.. the

cat_id is the 1st variable from the drop down menu.

1 = the whole site. (would need to seach * from table)

and 2-18 are the other categories. (so specifically search only)

and the 2nd string that is passed is the search variable.

that is. search_text
 
You will need somethings like this:

if you can't use full-text-search on your table use this query to enable it:
Code:
ALTER TABLE table_name ADD FULLTEXT(column1_name, column2_name);

than:
PHP:
//to save data from  html form into 2 variables
$cat_id =  intval($_POST['cat_id']);
$search_text = mysql_real_escape_string($_POST['search_text']);


//execute query
if ($cat_id>1){//for specifically search
$query = "SELECT *, MATCH (art_text) AGAINST ("$search_text") FROM `articles` WHERE  MATCH (art_text) AGAINST("$search_text") AND `cat_id`= "$cat_id" ORDER BY MATCH (art_text) AGAINST ("$search_text") DESC";

$results = mysql_query($query);}

elseif ($cat_id==1){//search in whole site
$query = "SELECT *, MATCH (art_text) AGAINST ("$search_text") FROM `articles` WHERE  MATCH (art_text) AGAINST("$search_text") ORDER BY MATCH (art_text) AGAINST ("$search_text") DESC";

$results = mysql_query($query);
}
and now you can display your search :)

regards
Cyklotrial

ps. i'm tired and I wrote from memory without testing so it can have bugs :)
 
yeah that didnt quite work.

I messaged you about it. I tested the variables and there being passed, but I cant quite seem to see whats wrong with the script.
 
Back
Top