simon551 Posted July 21, 2007 Share Posted July 21, 2007 Hi, Can you use an array as a criteria in a new query? just wondering if it is possible to do something like this: $queryA="SELECT * FROM table1 WHERE x=1"; $resultA=mysql_qry($queryA); while ($array=mysql_fetch_array($resultA)) { $queryB="SELECT * FROM table2 WHERE y IN($array)"; } Thanks in advance, -s Quote Link to comment Share on other sites More sharing options...
marcus Posted July 21, 2007 Share Posted July 21, 2007 You would have to give "$array" a field parameter to work. WHERE y IN($array[x]) Quote Link to comment Share on other sites More sharing options...
simon551 Posted July 21, 2007 Author Share Posted July 21, 2007 Thanks! That works. What if I wanted to use this in a page without writing the whole query in to use it inline. I would normally keep my queries in a separate page. This works: $queryA="SELECT * FROM table1 WHERE x=1"; $resultA=mysql_qry($queryA); while ($array=mysql_fetch_array($resultA)) { $queryB="SELECT * FROM table2 WHERE y IN($array[x])"; do { echo $row['y_1'].'<br />; } while ($row=mysql_fetch_assoc($queryB)); } } But feels like it could be a bit much although I'm too new to really know. This doesn't work but I'm not sure why: $queryA="SELECT * FROM table1 WHERE x=1"; $resultA=mysql_qry($queryA); while ($array=mysql_fetch_array($resultA)) { $queryB="SELECT * FROM table2 WHERE y IN($array[x])"; } do { echo $row['y_1'].'<br />; } while ($row=mysql_fetch_assoc($queryB)); I realize your getting away from the while array logic, but it would be much cleaner to be able to write it like this in the page ( just the echo part without the query.) 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.