Id have a setup something like this
page | query | hits
You should make sure page and query are indexed as they will be used in the WHERE clause. I would also make these as two fields rather than just one because you may want to search based on page and see all the different queries.
Then code below
// you may want to use the database specific escape function
$page = addslashes( $_SERVER["PHP_SELF"] );
$query = addslashes( $_SERVER["QUERY_STRING"] );
$cond = array();
$cond[] = "page='$page'";
$cond[] = "query='$query'";
$cond = join( " AND ", $cond );
query( "SELECT page FROM mytblname WHERE $cond" );
if ( next_record() )
{
query( "UPDATE mytblname SET hits = hits + 1 WHERE $cond" );
}
else
{
query( "INSERT INTO mytblname VALUES( '$page', '$query', 1 )" );
}
Of course you can make this a function, no actually i recommend you do so. I hope this helps