oavs Posted April 12, 2006 Share Posted April 12, 2006 Hi,I have a website wich has a search facility to search our database. Is there way of storing or saving every keyword entered that used in the serach box?.. and how?Basicly at the moment it does search through the database and displays the results. What I need to know is what people is entering into the search box to carry on their searches .can some one plese have a guided explanation how this could be done so that it searches > displays the search results but records the keyword entered without letting the user know.Thanks in advance Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 12, 2006 Share Posted April 12, 2006 Quite a simple thing to do, first make a new table called something like "searchstrings" and after you get the search text from the user to start performing a search, use a query to INSERT it into the searchstrings table.That way you can keep track of everything that the users are searching for. Quite a useful feature because if you can see what people are using the seach feature to look for the most you know to promote the visibility of the items to prevent users having to search for them. Quote Link to comment Share on other sites More sharing options...
oavs Posted April 12, 2006 Author Share Posted April 12, 2006 Hi That is exacly what I need to do but not sure how. Have a look at my code if you could and advise if you can futher please.I have following code above the <body> tag [code]<?phpinclude_once "myconnect.php";function left($cid){$keyword="";$type=1;$radio=1;if(isset($_REQUEST["keyword"]) && $_REQUEST["keyword"]<>"")$keyword=$_REQUEST["keyword"];if(isset($_REQUEST["type"]) && $_REQUEST["type"]<>"")$type=$_REQUEST["type"];if(isset($_REQUEST["radio"]) && $_REQUEST["radio"]<>"")$radio=$_REQUEST["radio"];?>[/code]then I have the search form - [code]<form name="form2" method="post" action="/manage/showcategory.php"> <input name="keyword" type="text" value="<? //echo $keyword;?>" style="width:115px; background:#ffffff url(/images/pwsearch.gif) no-repeat center;" onmouseover="this.style.backgroundImage = 'none'"/><input type="submit" name="Submit2" value="Go" /> <select name="cid"> <option value=0 selected >Select a prefix</option> <? $cats=mysql_query("select * from sbclassified_categories where pid=0 order by cat_name"); while($rst=mysql_fetch_array($cats)) { ?> <option value="<? echo $rst["id"]; ?>" <? if($rst["id"]==$cid) echo " selected ";?> <? echo $rst["cat_name"]; ?></option> <? }//end while ?> </select> <select name="type"> <option value=1 <? if($type==1) echo " selected ";?>>Current</option> <option value=3 <? if($type==3) echo " selected ";?>>New Today</option> <option value=4 <? if($type==4) echo " selected ";?>>Ending Today</option> <option value=5 <? if($type==5) echo " selected ";?>>Expired</option> <option value=6 <? if($type==6) echo " selected ";?>>All</option> </select> <input name="radio" type="radio" value="1" <? if($radio==1) echo " checked ";?> /> Item & desc <input type="radio" name="radio" value="2" <? if($radio==2) echo " checked ";?> /> Item # <input type="radio" name="radio" value="3" <? if($radio==3) echo " checked ";?> /> Vendor </form>[/code] Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 12, 2006 Share Posted April 12, 2006 Sorry for the late reply, I read the boards at work and had to go out and update two PCs but I'm at home now.I see by the second script that you're using method="post" in the HTML part so I advise changing all of the $_REQUEST[] to $_POST[].This line:[code]if(isset($_REQUEST["keyword"]) && $_REQUEST["keyword"]<>"")$keyword=$_REQUEST["keyword"];[/code]Can be replaced with this line:[code]if ($_POST['keyword']) {$keyword=$_POST['keyword'];}[/code]Makes the script a bit smaller and easier to read.By the looks of it you need a table in the database called searchdata with 4 fields. First set as the primary key and also to auto increment. Second would be the keyword, varchar, next two would be to contain the type and radio, both tinyint.In the first script you posted just before you terminate the PHP section add something like this:[code]mysql_query("INSERT INTO searchdata (`keyword`,`type`,`radio`) VALUES ('$keyword','$type','$radio')");[/code]When it comes to setting the datatype for keyword to VARCHAR set a length that you feel comfortable with. If you're not expecting them to exter more than, say 20 characters then set it to 20 but don't forget to limit the input of keyword in the HTML <input> tag with maxlength. Example:[code]<input type="text" name="keyword" maxlength="20">[/code]That way the user is prevented from entering more than 20 characters and prevents data being "chopped off" when its added to the database. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.