0

I am new in php.Instead of using

$result=mysql_fetch_assoc($qry)
$result['id']; 

i want to pass a variable instead of id like this

$id='id';
$result=mysql_fetch_assoc($qry)
    $result[$id]; 

I have tried like this but not working.How can i pass a variable as argument to fetch a value from database

4

1 Answer 1

1

mysql_fetch_assoc provides you the multi-dimentional array.

$result = array(
    array('id'=>`some_value`)
);

So you can do like this:

$ID = "id";
foreach($result as $row) {
    echo $row[$ID] . "\n";
}

NOTE:

Please, don't use mysql_* functions in new code.

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.