Jump to content


Photo

how to save search keywords typed in search box


  • Please log in to reply
3 replies to this topic

#1 oavs

oavs
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationDownunder

Posted 12 April 2006 - 10:58 AM

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

#2 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 12 April 2006 - 11:39 AM

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.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#3 oavs

oavs
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts
  • LocationDownunder

Posted 12 April 2006 - 12:24 PM

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
<?php
include_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"];
?>

then I have the search form -

<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  &amp; 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>


#4 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 12 April 2006 - 04:51 PM

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:
if(isset($_REQUEST["keyword"]) && $_REQUEST["keyword"]<>"")
$keyword=$_REQUEST["keyword"];
Can be replaced with this line:
if ($_POST['keyword']) {$keyword=$_POST['keyword'];}
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:
mysql_query("INSERT INTO searchdata (`keyword`,`type`,`radio`) VALUES ('$keyword','$type','$radio')");
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:
<input type="text" name="keyword" maxlength="20">
That way the user is prevented from entering more than 20 characters and prevents data being "chopped off" when its added to the database.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users