Jump to content

Getting information from DB array


Ryflex

Recommended Posts

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]'];

Link to comment
https://forums.phpfreaks.com/topic/221958-getting-information-from-db-array/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.