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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.