Ryflex Posted December 17, 2010 Share Posted December 17, 2010 Hi all, I have an array $n[] and have made a DB query with fetch_array ($result[]). Now I'm trying to get the information out of the $result[] with $n[] so I made the following and it doesn't work. I checked if they're filled and they are and when I enter in the $result[] array with hardcoded info I do get what I need but I need it trough the array... Can anyone help me out?? Thnx Ryflex $sql = "SELECT * FROM units WHERE member_id = '$member_ID'"; $result = mysql_fetch_array(mysql_query($sql)) or die("Could not find amount of troops"); $troop_one = $result['$n[0]']; $troop_two = $result['$n[1]']; $troop_three = $result['$n[2]']; $troop_four = $result['$n[3]']; Quote Link to comment Share on other sites More sharing options...
girish.kc Posted December 17, 2010 Share Posted December 17, 2010 Change Change $result['$n[0]']; to Change $result[$n[0]]; [ie, Remove the single quote]. PHP will consider the content inside single quote as string. If you are using the variable, it has to be enclosed by double quote, not single quote. OR use another variable $tmp = $n[0]; $result[$tmp]; Girish Quote Link to comment Share on other sites More sharing options...
Ryflex Posted December 17, 2010 Author Share Posted December 17, 2010 great it works. THNX Ryflex 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.