0

I tried to print a record in MySQL, but got an error. I have this method:

$aa = DB::select("select user from statystyki where id = '10'");
print $aa->user;

The function mysql_fetch_array is not working.

2 Answers 2

2

DB::select returns an array of objects. If you var_dump($aa), you can see the structure, which should look like this:

array(
    0 => object(stdClass)(
        'user' => 'username'
    )
)

You want to print the user this way:

$aa[0]->user;
Sign up to request clarification or add additional context in comments.

Comments

0

Make one loop. Try this way

$aa = DB::select("select user from statystyki where id = '10'");
foreach($aa as $user)
{
     print $user->user;
}

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.