Daney11 Posted December 12, 2007 Share Posted December 12, 2007 Hey guys, I have an array <?php $location = array( 'af' => 'Afghanistan', 'al' => 'Albania', 'dz' => 'Algeria', 'as' => 'American Samoa', 'ad' => 'Andorra', 'ao' => 'Angola', 'ai' => 'Anguilla', 'aq' => 'Antarctica', 'ag' => 'Antigua And Barbuda', 'ar' => 'Argentina', 'am' => 'Armenia', 'aw' => 'Aruba', 'au' => 'Australia'); ?> etc And i have a mysql row called $member_nation. Im using <?php foreach ($location as $member_nation) { echo $member_nation; } ?> But it is not getting the information from the array. Any ideas? Thanks Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/ Share on other sites More sharing options...
kenrbnsn Posted December 12, 2007 Share Posted December 12, 2007 You code should be something like this <?php <?php foreach ($member_nation as $mn) echo $location[$mn]; ?> You were looping through the wrong array. Ken Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413249 Share on other sites More sharing options...
Daney11 Posted December 12, 2007 Author Share Posted December 12, 2007 Thanks Ken, However it is still not pulling the data from the database. Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413250 Share on other sites More sharing options...
Daney11 Posted December 12, 2007 Author Share Posted December 12, 2007 I actually cannot see were the error is. <?php foreach ($member_nation as $mn) {echo $location[$mn]; } ?> Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413274 Share on other sites More sharing options...
kenrbnsn Posted December 12, 2007 Share Posted December 12, 2007 Please post more of your code. Ken Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413276 Share on other sites More sharing options...
Daney11 Posted December 12, 2007 Author Share Posted December 12, 2007 My code works fine. What code would you like to see. If i echo $member_nation it works fine. For example it will echo "en". <?php $location = array( 'af' => 'Afghanistan', 'al' => 'Albania', 'dz' => 'Algeria', 'as' => 'American Samoa', 'ad' => 'Andorra', 'ao' => 'Angola', 'ai' => 'Anguilla', 'aq' => 'Antarctica', 'ag' => 'Antigua And Barbuda', 'ar' => 'Argentina', 'am' => 'Armenia', 'aw' => 'Aruba', 'au' => 'Australia'); 'en' => 'England'); ?> Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413279 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 If i put <?php foreach($location as $member_nation => $value) { echo $value; } ?> that echos out all the values on my array Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413302 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 $member_nation = MySQL field containing Nation i.e. en = England <?php $location = array( 'af' => 'Afghanistan', 'en' => 'England'); ?> foreach (array_expression as $value) foreach ($location as $member_nation) ?? Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413330 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 what is your problem again with that codes? Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413332 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 Nothing is echoing out. and if i put foreach ($location as $member_nation) {echo "$member_nation <br />";} ?> all the values in the array echo out. Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413334 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 foreach ($location as $key=> $member_nation) { echo $key; echo "$member_nation"; } ?> try something like that Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413337 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 that echos out every single value within my array. <?php $location = array( 'af' => 'Afghanistan', 'al' => 'Albania', 'dz' => 'Algeria', 'as' => 'American Samoa', 'ad' => 'Andorra', 'ao' => 'Angola', 'ai' => 'Anguilla', 'aq' => 'Antarctica', 'ag' => 'Antigua And Barbuda', 'ar' => 'Argentina', 'am' => 'Armenia', 'aw' => 'Aruba', 'au' => 'Australia', 'at' => 'Austria', 'aw' => 'Aruba', 'ax' => 'Aland Islands', 'az' => 'Azerbaijan', 'bs' => 'Bahamas', 'bh' => 'Bahrain', 'bd' => 'Bangladesh', 'bb' => 'Barbados', 'by' => 'Belarus', 'be' => 'Belgium', 'bz' => 'Belize', 'bj' => 'Benin', 'bm' => 'Bermuda', 'bt' => 'Bhutan', and so on I need it to echo out a specific value with is the $member_nation Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413338 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 ok give us your desired out put ! so we can finish this thing Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413342 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 Basically. I have an array full of countrys en = england 'by' => 'Belarus', 'be' => 'Belgium', 'bz' => 'Belize', etc. I have a $member_nation in the database which contains the 2 letter from countrys i.e. en I would like to echo out the member_nation as the country name i.e. England Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413347 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 lets say $teng has all the data in your db foreach ($location as $key=> $member_nation) { if(in_array($key,$teng)){ echo "$member_nation"; } } ?> maybe Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413364 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 $member_nation has the data in the database Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413371 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 print the value of $member_nation here like what you did form $location is that array or not.. Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413378 Share on other sites More sharing options...
Daney11 Posted December 13, 2007 Author Share Posted December 13, 2007 an hour and a half staying up this late and all i needed to do was <?php echo $location[$member_nation]; ?> omg lol. thanks for all ur help. <3 Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413384 Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 Link to comment https://forums.phpfreaks.com/topic/81420-solved-array/#findComment-413388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.