neel
(Kazi Neel)
1
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 $P[1];
........
?>
Can you tell me how to define sql command array and print like that?
Y11
(Y!!)
2
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);
neel
(Kazi Neel)
3
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?
neel
(Kazi Neel)
5
Would you plz explain how to use this?
tri
(tri - Tommy Riboe)
6
Excerpt from the guide:
http://www.yiiframework.com/doc/guide/database.dao
HTH
/Tommy
neel
(Kazi Neel)
7
Thanx, Problem solved.
$column=$command->queryColumn();