shadiadiph Posted May 14, 2010 Share Posted May 14, 2010 MM never had to use the array_combine functiion before but I can't seem to get it working its only returning the first two values in the table and an array with one value I would of thought that when its in the while loop it would return the lot?? function getcountrylist(){ $cc=array(); $cn=array(); $countrylist=array(); $countryquery = "SELECT * FROM `cc`"; $rcountryquery = mysql_query($countryquery); while($row=mysql_fetch_array($rcountryquery)){ $cc= array($row["cc"]); $cn= array($row["cn"]); $countrylist= array_combine($cc,$cn); return $countrylist; } //-----END while($row=mysql_fetch_array($rcountryquery)) } Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/ Share on other sites More sharing options...
kenrbnsn Posted May 14, 2010 Share Posted May 14, 2010 You have the return statement inside your loop, so it's doing one iteration. I'm not sure what you want to return, but try this: <?php function getcountrylist(){ $countrylist=array(); $countryquery = "SELECT * FROM `cc`"; $rcountryquery = mysql_query($countryquery); while($row=mysql_fetch_assoc($rcountryquery)){ $countrylist[]= array($cc,$cn); } return $countrylist; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058060 Share on other sites More sharing options...
shadiadiph Posted May 14, 2010 Author Share Posted May 14, 2010 mm thanks that didn't work but put me on the right track kind of I now have function getcountrylist(){ $cc=array(); $cn=array(); $countrylist=array(); $countrylist=array(); $countryquery = "SELECT * FROM `cc`"; $rcountryquery = mysql_query($countryquery); while($row=mysql_fetch_assoc($rcountryquery)){ $cc = array($row['cc']); $cn = array($row['cn']); $countrylist[]=array_combine($cc,$cn); } return $countrylist; } Only thing is it returns an array in an array Array ( [0] => Array ( [AP] => Asia/Pacific Region ) [1] => Array ( [AU] => Australia ) [2] => Array ( [uS] => United States ) [3] => Array ( [CA] => Canada ) how do i get rid of Array ( [0] => Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058063 Share on other sites More sharing options...
shadiadiph Posted May 14, 2010 Author Share Posted May 14, 2010 how do i get rid of Array ( "[0]" => dont know why but in here doesn't show the "[0]" Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058064 Share on other sites More sharing options...
shadiadiph Posted May 14, 2010 Author Share Posted May 14, 2010 zero 0 in square brackets Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058065 Share on other sites More sharing options...
greatstar00 Posted May 14, 2010 Share Posted May 14, 2010 the zero is the index not the value in the array Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058067 Share on other sites More sharing options...
shadiadiph Posted May 14, 2010 Author Share Posted May 14, 2010 I am trying to get to this so it returns the cc as the key and the cn as the value so it returns an array like Array ( [AP] => Asia/Pacific Region, [AU] => Australia, [uS] => United States etc.... Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058070 Share on other sites More sharing options...
kenrbnsn Posted May 14, 2010 Share Posted May 14, 2010 If you surround the array values with tags when posting to the forum, they will look much better. Try this code to get the array you want: <?php function getcountrylist(){ $countrylist=array(); $countryquery = "SELECT * FROM `cc`"; $rcountryquery = mysql_query($countryquery); while($row=mysql_fetch_assoc($rcountryquery)){ $countrylist[$row['cc']]= $row['cn']; } return $countrylist; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058072 Share on other sites More sharing options...
shadiadiph Posted May 14, 2010 Author Share Posted May 14, 2010 thank you ken Quote Link to comment https://forums.phpfreaks.com/topic/201699-array_combine-query/#findComment-1058075 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.