2

I'm a beginner in this framework. Though I have gone over the basics, there is one thing which is troubling me. As of now, I'm using

$group_sql = "SELECT uid FROM {$table}";
$group_users = Yii::app()->db->createCommand($group_sql)->queryAll();
print_r($group_users);

results in

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

    [1] => Array
        (
            [uid] => 3
        )

    [2] => Array
        (
            [uid] => 4
        )

    [3] => Array
        (
            [uid] => 5
        )

)

But I'd like to change the format in which the data is returned. What I'm looking for is something like

Array
(
    [0] => 2
    [1] => 3
    [2] => 4
    [3] => 5
)

OR

Array
(
    [uid] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 4
            [3] => 5
        )
)

I'm aware that I can go through the documentation and get my answer, but due to time constraints, I'm taking the liberty to shamelessly ask this over here.

Thanks in advance.

1 Answer 1

4

Use queryColumn() method instead of queryAll()

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

3 Comments

Bingo! +1 and will accept as answer when the time limit wears off.
If it's not much trouble, can you point me to the link where these methods have been documented so that I can go through them and see what other options I can use in future?
yiiframework.com/doc/api/1.1/CDbCommand here is all you need regarding CDbCommand class. Similar methods are queryAll(), queryColumn(), queryRow(), queryScalar()

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.