I'm trying to get a count of the number of records in a database that have
the keyword "cat", for example. Below is the original code; I added the
query with count at the bottom of this code but it doesn't seem to be
working.  I just get a return of "4" which doesn't correspond correctly with
the true number of records (also, I get the same return of "4" regardless of
the keyword I want to search).

All I want to do is put the record number in parantheses next to the
category so that people visiting the site will be able to tell if new
submissions have been added since they last visited.

Am I missing something really obvious? 

Thanks for your help, Shawna

<? 


// original code

if($search == "or"){
        $op = "or";
        $query = "0";
}else{
        $op = "and";
        $query = "1";
        };

if($title){
        $title = addslashes($title);
        $query .= " " . $op . " title like '%$title%'";
        };
if($keywords){
        $foo = "(0";
        $keywords = addslashes($keywords);

        $strings = explode(" ", $keywords);
        $num_strings = count($strings);

        for($i=0;$i<$num_strings;$i++){
                $curstring=$strings[$i];

                $foo .= " or keywords like '%$curstring%'";
                };
        
        $query .= " " . $op . " $foo)";
        };
if($category){
        $query .= " " . $op . " category like '%$category%'";
        };
if($type){
        $query .= " " . $op . " type like '%$type%'";
        };      
if($language){
        $language = addslashes($language);
        $query .= " " . $op . " language like '%$language%'";
        };
if($region){
        $query .= " " . $op . " region like '%$region%'";
        };
if($author){
        $author = addslashes($author);
        $query .= " " . $op . " author like '%$author%'";
        };

$offset = addslashes($offset);
if(!($offset)){$offset = 0;};

$results = mysql_db_query("$db", "select id, title,
date_format(sources.datetime, '%e/%c/%y') as datetime, category, type,
description from sources where  ( $query ) and approved = 'y' order by id
desc limit $offset, 10");


//my code
$keywordsearch = mysql_db_query("$db", "select count(*) from sources where
keywords = 'cat' and approved = 'y'");

?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to