This topic is locked

Log Search Queries in Tbl

12/12/2011 1:30:42 PM
PHPRunner General questions
W
weisd author

I am wanting to add a record to a table named Search Query each time a visitor uses the search function.
I assume it will be a variant of this code int the Before SQL Event,
global $conn;
$strSQLInsert = "insert into TableName (Field1, Field2)
values (Value1, Value2)";
db_exec($strSQLInsert,$conn);

I want Value2 to be the time and date and value one to be the visitor's search term.
Once I have this, I would like to have that table only keep the last 500 records...
I want to have this work for either advanced or basic search and alos for the code below which is on my View Page.
<FORM name=frmSearch action="http://www.weisd.com/test/WEISD_TBL_list.php"; method=get target=_self>

<input type="Hidden" name="a" value="search">

<input type="Hidden" name="value" value="1">

<INPUT type=text name="SearchFor"

onkeydown="e=event; if(!e) e = window.event; if (e.keyCode != 13) return true; e.cancel = true; frmSearch.submit(); return false;"

>

<input type="Hidden" name="SearchOption" value="Contains">

<input type="Hidden" name="SearchField" value="">
<input type="submit" value="Search">

</FORM>

I am already capturing Basic, advance, and SearchFor in a Before Display event to use for pagetitle etc in the resulting search results so Iassume it is just a matter of setting Value1 to the query and value2 to the date but I am not sure of the syntax need...

W
weisd author 12/12/2011

This is working so far but still want to limit the tbl to 200 records or so...
global $conn;
{

$Number = Now();

}
$Qry = "";

$SecondTerm = "";

$FirstTerm = "";
if(isset($_REQUEST['ctlSearchFor']))
{

$Qry = $_REQUEST['ctlSearchFor'];

}
global $strTableName;
if (isset($_SESSION[$strTableName.'_advsearch']))
{
$searchClauseObj = unserialize($_SESSION[$strTableName.'_advsearch']);
}
$fieldSearchData = $searchClauseObj->getSearchCtrlParams("FieldName");
$fieldSearchData = $searchClauseObj->_where[$strTableName."_srchFields"];
for($i=0; $i<count($fieldSearchData); $i++){
$nmbr = count($fieldSearchData);
$fName = $fieldSearchData[$i]['fName'];
$val1 = $fieldSearchData[$i]['value1'];
$val2 = $fieldSearchData[$i]['value2'];
$srchCat = $fieldSearchData[$i]['opt'];
$srchNot = $fieldSearchData[$i]['not'];
If ($i == 0)

{

$FirstTerm = $val1;
}
If ($i == 1)

{

$SecondTerm = $val1;
}
$visitorsearch = $FirstTerm." ".$SecondTerm;
$Qry = $visitorsearch;
}
if(isset($_REQUEST['SearchFor']))

{

$Qry = $_REQUEST['SearchFor'];

}
$strSQLInsert = "insert into Search_Queries (QueryField, DateField)

values ('".$Qry."','".$Number."')";
db_exec($strSQLInsert,$conn);