Link to home
Start Free TrialLog in
Avatar of gorexy
gorexy

asked on

Simple array quesion

HI,
I did the following

  $result=mysql_query($sqlString);
  $rv = array();
  while($ret=mysql_fetch_array($result,MYSQL_ASSOC)){
          $rv[]=$ret;
 print_r($rv);
  }

The result is:
Array ( [0] => Array ( [Char_ID] => 274 [Char_Pos_X] => -5.96249 [Char_Pos_Y] => 3.91121 [Char_Pos_Z] => -34.7117 [Char_Dir_X] => -0.49003 [Char_Dir_Y] => 1e-006 [Char_Dir_Z] => -0.871706 ) )

but when i want to retrieve the first value
I use

$rv[0]->Char_ID;

It cannot show the result i.e 274 in my example.
what's wrong?
Avatar of BogoJoker
BogoJoker

Hi gorexy,

Why not just:
$firstValue = $rv[0]?
Do you need the arrow format?

Joe P
Avatar of gorexy

ASKER

ok let me try first
Ijust need to arrange the result in a row no special format
Avatar of gorexy

ASKER

sorry how to use your soluation in my example?
$charid = $rv[0];  // Now $charid is 274

Joe P
Avatar of gorexy

ASKER

Sorry fail

I put

$charid = $rv[0];
print $charid;

it said

ARRAY
How about:
$array = $rv[0];
$charid = $array['Char_ID'];

If that works you might beable to use:
$charid = $rv[0]['Char_ID'];
Avatar of gorexy

ASKER

sorry same result

only display ARRAY
If that suggestion doesnt work then I'm afraid I don't know.  Try this debugging.
$array = $rv[0];
print_r($array);
$charid = $array['Char_ID'];

That is what I had above, only now I'm printing $array.  Show me what that prints, it should print out:
Array ( [Char_ID] => 274 [Char_Pos_X] => -5.96249 [Char_Pos_Y] => 3.91121 [Char_Pos_Z] => -34.7117 [Char_Dir_X] => -0.49003 [Char_Dir_Y] => 1e-006 [Char_Dir_Z] => -0.871706 )

I have no clue why it wouldn't.
Joe P
Avatar of gorexy

ASKER

$array = $rv[0];
print_r($array);


it shows ARRAY only

nothign else
Avatar of gorexy

ASKER

it is funny

How about:
$array = $rv[0];
$charid = $array['Char_ID'];

I use your code to print but fail

but now use this as you suggested, it works

$charid = $rv[0]['Char_ID'];

$charid=274
Avatar of gorexy

ASKER

I just wonder why cannot use  '->' to retrieve value
ASKER CERTIFIED SOLUTION
Avatar of BogoJoker
BogoJoker

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gorexy

ASKER

anyway for your further sugestions!
Avatar of gorexy

ASKER

Thanks!
Did you get it working or did you use the alternate solutions?  =)
Joe P
Avatar of gorexy

ASKER

it works now
 $charid = $rv[0]['Char_ID'];

but i face another problem..let see can I fix it first