oneg Posted December 22, 2008 Share Posted December 22, 2008 First my hosting information, and program versions: - I have this table (mysql) with 3 columns: ID Country Target 1 US North America 2 ES EUROPE 3 ES West Europe 4 SA Africa 5 US American Continent If I do this: $resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'); $rowtargetcr = mysql_fetch_row ($resulttargetcr); I only get first result. 1) North America The problem is that I want to get all results: 1) North America 2) American Continent - How can I get all results? - I then want to use this results (all of them) on another query: $rowtargetcreach = "'" . implode("', '", $rowtargetcr) . "'"; $query2 = mysql_query("SELECT Target2 FROM table2 WHERE trgcountry='$rowtargetcreach'); But It doesnt works either. Please help, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/ Share on other sites More sharing options...
Maq Posted December 22, 2008 Share Posted December 22, 2008 To display all the info you need a while loop like this: $resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'") or die(mysql_error()); while($rowtargetcr = mysql_fetch_row ($resulttargetcr)) { echo $rowtargetcr['ID'] . " - " . $rowtargetcr['Country'] . " - " . $rowtargetcr['Target'] . " "; } Then just do your other query inside this while loop. Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721063 Share on other sites More sharing options...
oneg Posted December 22, 2008 Author Share Posted December 22, 2008 thank you for your answer. but I need the results out of the while loop. Its there a way to get all the results outside the while loop? I tried your code, and then this: $rowtargetcreach = "'" . implode("', '", $rowtargetcr) . "'"; But it doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721074 Share on other sites More sharing options...
fenway Posted December 22, 2008 Share Posted December 22, 2008 Its there a way to get all the results outside the while loop? Feel free to push onto an array if you so choose. Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721582 Share on other sites More sharing options...
Maq Posted December 22, 2008 Share Posted December 22, 2008 Create an associative array just like what the query returns. Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721599 Share on other sites More sharing options...
oneg Posted December 23, 2008 Author Share Posted December 23, 2008 Its there a way to get all the results outside the while loop? Feel free to push onto an array if you so choose. Thank you for your answer. Can you give me some code example? I have tested a few methods but I do not know how to make it work. If I do a while loop, and foreach, I can not get the results outside the loop. If I do not make a while loop, I can not get all the results... thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721837 Share on other sites More sharing options...
oneg Posted December 23, 2008 Author Share Posted December 23, 2008 I want to learn. Do you mean I must try this funtion?: http://us.php.net/function.array-push Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721920 Share on other sites More sharing options...
trq Posted December 23, 2008 Share Posted December 23, 2008 $resultarray = arry(); $resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'") or die(mysql_error()); while($rowtargetcr = mysql_fetch_row ($resulttargetcr)) { $resultarray[] = $rowtargetcr['Target']; } This will give you an array called $resultarray which contains all your results. I then want to use this results (all of them) on another query: I would highly recommend taking a look at the tutorial on www.phpfreaks.com in regard to joins and unions before executing multiple queries using one result from another. You can usually get what you need done in one query. Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721928 Share on other sites More sharing options...
oneg Posted December 23, 2008 Author Share Posted December 23, 2008 $resultarray = arry(); $resulttargetcr = mysql_query("SELECT Target FROM table WHERE Country='US'") or die(mysql_error()); while($rowtargetcr = mysql_fetch_row ($resulttargetcr)) { $resultarray[] = $rowtargetcr['Target']; } This will give you an array called $resultarray which contains all your results. I then want to use this results (all of them) on another query: I would highly recommend taking a look at the tutorial on www.phpfreaks.com in regard to joins and unions before executing multiple queries using one result from another. You can usually get what you need done in one query. THANK YOU very much, it works great. And I will take a look at the tutorial on www.phpfreaks.com in regard to joins and unions.... Quote Link to comment https://forums.phpfreaks.com/topic/137960-solved-target-results-con-column-question/#findComment-721959 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.