Re: query string - count for records with keywords

From: Date: Sun, 09 Sep 2001 01:21:01 +0000
Subject: Re: query string - count for records with keywords
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66567@lists.php.net to get a copy of this message
That '4' you see is that this is the FOURTH thing you've asked MySQL to do in this script. You need to use http://php.net/mysql_result or other similar function to get your actual answer. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: <sgibbs@vt.globalhealth.org> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Saturday, September 08, 2001 12:04 PM Subject: query string - count for records with keywords > 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"); > > > file://my code > $keywordsearch = mysql_db_query("$db", "select count(*) from sources where > keywords = 'cat' and approved = 'y'"); > > ?>

« previous php.general (#66567) next »