Hi there, I made some of the changes you said below, and when I check the query I get this:
The query is SELECT distinct description, email, url, country, category, type, rating from search6 WHERE description LIKE '%word%'AND category = 'Automotive' AND country = 'Austria' AND type = 'Car Rental' ORDER BY description so to me it doesn't appear to be putting the array item in there, or am I wrong? I am confused, thanks for your help. Regards Chris > On Saturday 19 January 2002 13:11, Chris Payne wrote: > > Hi there, > > > > I know this is probably a REALLY simple problem, but I can't get this to > > work. I need to get it to cycle through each word and do a search, I used > > this as sent from Beau Lebens (Thank you) but I can't get it to work. It > > works on 1 word querie but if I enter more than 1 it says can't execute > > query, please help and tell me what i'm doing wrong :-) > > Anytime you're putting a query to a db and you're not getting the results > expected you should echo the query to see what you're actually sending to the > db. You could also copy and paste the query into the mysql-client to see what > pops out. > > > > $words = explode(" ", $test); > > > > // create connection > > $connection = mysql_connect("Localhost","!!!","!!!") or die("Couldn't make > > a connection."); > > > > // select database > > $db = mysql_select_db("tas", $connection) > > or die("Couldn't select database."); > > > > $sql = "SELECT distinct description, email, url, country, category, type, > > rating from search6 WHERE "; foreach ($words as $word) { > > $sql .= "description LIKE '%word%'"; > > You should probably be using: > > $sql .= " description LIKE '%word%' OR "; # note the spaces > > > > } > > After the foreach loop you need to remove the trailing "OR ". That is you > need to remove the last 3 characters from $sql. > > > > > $sql .= "AND category = '$category' AND country = '$country' AND type = > > '$type' ORDER BY description"; > > This would be a good place to: > > echo("The query is $sql<br>"); > > > > $sql = mysql_query($sql,$connection) > > or die("Couldn't execute query."); > > > hth > -- > Jason Wong -> Gremlins Associates -> www.gremlins.com.hk > > /* > "Why must you tell me all your secrets when it's hard enough to love > you knowing nothing?" > -- Lloyd Cole and the Commotions > */ > > -- > PHP Database 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] -- PHP Database 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]