shawjames Posted June 19, 2008 Share Posted June 19, 2008 I do my SQL query like normal: <? $result = mysql_query($query); while($list = mysql_fetch_array($result)){ //do stuff } ?> I would like to do multiple queries, and join them into one $result before starting the while() loop. Is this possible? If so, how would I do this on the PHP side? Or, would I need to format my $query to fetch everything I need in just one query? Quote Link to comment https://forums.phpfreaks.com/topic/110949-join-multiple-query-before-mysql_fetch_array/ Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 You cannot join multile results into one. If you can use JOIN in your SQL to get all the data in one query, then your problems will be solved. Quote Link to comment https://forums.phpfreaks.com/topic/110949-join-multiple-query-before-mysql_fetch_array/#findComment-569266 Share on other sites More sharing options...
shawjames Posted June 19, 2008 Author Share Posted June 19, 2008 You cannot join multile results into one. If you can use JOIN in your SQL to get all the data in one query, then your problems will be solved. Okay, then I think I need help with my query. these are the two I want to join: SELECT * FROM table WHERE flag='Y' SELECT * FROM table WHERE flag='N' LIMIT 50 So I want to have all with flag=Y and 50 with flag=N all in the same query. Is this easy? Quote Link to comment https://forums.phpfreaks.com/topic/110949-join-multiple-query-before-mysql_fetch_array/#findComment-569355 Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 There is no logical reason I can think of to combine the two where you would run through them in the same loop. Quote Link to comment https://forums.phpfreaks.com/topic/110949-join-multiple-query-before-mysql_fetch_array/#findComment-569357 Share on other sites More sharing options...
shawjames Posted June 19, 2008 Author Share Posted June 19, 2008 There is no logical reason I can think of to combine the two where you would run through them in the same loop. So I want to get a list of all flagged entries, and 50 that are not flagged per execute. This script will run once per day in a cron job. Of the Flagged entries, (and the 50 that are not flagged), some checks will be done on each. Based on the check, some of these might be removed from the DB and the remaining will be flagged. This will recursively go through the entire table, until all are either flagged or deleted. New entries will come in not flagged, and will be checked when it is their turn in the "50 per day". Normally, I would do this with 2 separate queries and 2 separate loops. I want to know if it can be done with one loop? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/110949-join-multiple-query-before-mysql_fetch_array/#findComment-569398 Share on other sites More sharing options...
abdfahim Posted June 19, 2008 Share Posted June 19, 2008 if you want to do it in one loop anyway, you should use UNION function like SELECT * FROM table WHERE flag='Y' UNION SELECT * FROM table WHERE flag='N' LIMIT 50 Quote Link to comment https://forums.phpfreaks.com/topic/110949-join-multiple-query-before-mysql_fetch_array/#findComment-569450 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.