Array problem

Hey Guys

I have problem to print data array, here is my sql command

$P = Yii::app()->db->createCommand("SELECT test FROM Table WHERE table1_id = 1 ")->queryScalar();

I want to print

<?php echo $P[0];

  echo &#036;P[1];


  ........

?>

Can you tell me how to define sql command array and print like that?

queryScalar() returns a single value. queryAll() is what you want I guess, it returns array.

In order to get a number-indexed array, you must use it this way:


$P = Yii::app()->db->createCommand("SELECT test FROM Table WHERE table1_id = 1 ")->queryAll(false);

when I print

<item>’ .$P[0]. '</item>

<item>’ .$P[1]. '</item>

<item>’ .$P[2]. '</item>

I got this error

The value [Array] is not valid for this field. It must contain an integer.

here is my var_dump result

var_dump ($P);

array(7) { [0]=> array(1) { ["i"]=> string(3) "700" } [1]=> array(1) { ["i"]=> string(3) "701" } [2]=> array(1) { ["i"]=> string(3) "702" } [3]=> array(1) { ["i"]=> string(3) "703" } [4]=> array(1) { ["i"]=> string(3) "704" } [5]=> array(1) { ["i"]=> string(3) "750" } [6]=> array(1) { ["i"]=> string(2) "91" } }

I want to print this way

when I print

<item>’ .$P[0]. '</item>

<item>’ .$P[1]. '</item>

<item>’ .$P[2]. '</item>

any idea?

queryColumn()

Would you plz explain how to use this?

Excerpt from the guide:

http://www.yiiframework.com/doc/guide/database.dao

HTH

/Tommy

Thanx, Problem solved.

$column=$command->queryColumn();

:)