t_machine Posted November 1, 2006 Share Posted November 1, 2006 hi, I am wondering if anyone could help with this problem I am having.I need to check if values in a table match that in an array. example$myarray = array();$myarray['color']="red";$myarray['drink']="pepsi";$query =..... SELECT * FROM tablename Where in_array(column_name, $myarray)....Can something like that work or would i need to display the results first then check if in array?Thanks :) Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 1, 2006 Share Posted November 1, 2006 You can not use PHP and MySQL together in a query.You'll need to select everything from your database first and then use mysl_fetch_row and then use the in_array function. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 1, 2006 Share Posted November 1, 2006 Never heard of this function, but I'd imagine that if you're examing rows for multiple name/value pairs, you'd have to check each one after the query. Quote Link to comment Share on other sites More sharing options...
t_machine Posted November 5, 2006 Author Share Posted November 5, 2006 Thank you for your replies :)It would be very good if someday mysql would include a function like that. Quote Link to comment Share on other sites More sharing options...
shoz Posted November 5, 2006 Share Posted November 5, 2006 Perhaps a query can be constructed using the array to give the results you're looking for. You'd have to explain in greater detail how the array should be looked at in relation to the information in the database.For instance, if the keys aren't relevant to the search then you can use something similar to[code]<?php$query = 'SELECT * FROM table WHERE column IN ("'.implode('","', $array).'")';?>[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted November 6, 2006 Share Posted November 6, 2006 Yeah, I've even "cheated" before by using IN with CONCAT(), but it prevent the use of an index. The only other way is it use a self join. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.