gorexy
asked on
Simple array quesion
HI,
I did the following
$result=mysql_query($sqlSt ring);
$rv = array();
while($ret=mysql_fetch_arr ay($result ,MYSQL_ASS OC)){
$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?
I did the following
$result=mysql_query($sqlSt
$rv = array();
while($ret=mysql_fetch_arr
$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?
ASKER
ok let me try first
Ijust need to arrange the result in a row no special format
Ijust need to arrange the result in a row no special format
ASKER
sorry how to use your soluation in my example?
$charid = $rv[0]; // Now $charid is 274
Joe P
Joe P
ASKER
Sorry fail
I put
$charid = $rv[0];
print $charid;
it said
ARRAY
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'];
$array = $rv[0];
$charid = $array['Char_ID'];
If that works you might beable to use:
$charid = $rv[0]['Char_ID'];
ASKER
sorry same result
only display ARRAY
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
$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
ASKER
$array = $rv[0];
print_r($array);
it shows ARRAY only
nothign else
print_r($array);
it shows ARRAY only
nothign else
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
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
ASKER
I just wonder why cannot use '->' to retrieve value
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
anyway for your further sugestions!
ASKER
Thanks!
Did you get it working or did you use the alternate solutions? =)
Joe P
Joe P
ASKER
it works now
$charid = $rv[0]['Char_ID'];
but i face another problem..let see can I fix it first
$charid = $rv[0]['Char_ID'];
but i face another problem..let see can I fix it first
Why not just:
$firstValue = $rv[0]?
Do you need the arrow format?
Joe P