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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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]; } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 12, 2007 Share Posted December 12, 2007 Please post more of your code. Ken Quote Link to comment 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'); ?> Quote Link to comment 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 Quote Link to comment 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) ?? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
teng84 Posted December 13, 2007 Share Posted December 13, 2007 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.