0

i retrieved data from mysql table in php


  $array2=array(); while($q1=  mysql_fetch_assoc($result))
{    print_r($q1);
    $array2[]= $q['user_id'];
}

the print_r($q1) will output this

Array ( [user_id] => 1 ) Array ( [user_id] => 2 ) Array ( [user_id] => 4 ) 
. Now i want to assign these values into another array i.e
 $array2[]=$q['user_id'];
but when i echo $array2 this gives me result otherthan $print_r($q) i.e

Array ( [0] => [1] => [2] => ) 

my question is how can i get the value of [user_id]=>4 from this array

1 Answer 1

1

$q is different from $q1..

You need:

$array2[]= $q1['user_id'];

It should actually be throwing a warning about $q['user_id'] not being defined. Do you have error reporting turned on?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.