Welcome Guest, Not a member yet? Register   Sign In
Looping DB result() array
#1

[eluser]Snipper[/eluser]
Hi All,

I'm new to CI, I want to loop through the array result without giving the row name. not like below since it generates the result using row name.


foreach ($query->result() as $row)
{
echo $row->title;
echo $row->name;
echo $row->body;
}
#2

[eluser]CroNiX[/eluser]
Unclear of what you are asking.
#3

[eluser]oneos[/eluser]
Also unclear, but if you mean to say 'column' instead of 'row', this might be what you're looking for?

Code:
foreach ($query->result_array() as $row)
    foreach ($row as $column)
        echo $column;
#4

[eluser]InsiteFX[/eluser]
Why add another foreach to the view? When you can use CodeIgniter's Table Class after all isn't that what tbles are for displaying tubluar data!

InsiteFX
#5

[eluser]Snipper[/eluser]
Hi All,

I have generated query result which consist of more than 30 fields(table cloumns) and my purpose is to generate a Excel file using the result() array. If i loop the array using field name, I have to give all the fields. I just wanted loop the array without giving the filed name of the table.
#6

[eluser]Unknown[/eluser]
[quote author="InsiteFX" date="1306481628"][/quote]
#7

[eluser]stuckinphp[/eluser]
[quote author="oneos" date="1306465300"]Also unclear, but if you mean to say 'column' instead of 'row', this might be what you're looking for?

Code:
foreach ($query->result_array() as $row)
    foreach ($row as $column)
        echo $column;
[/quote]

Code:
foreach ($query->result_array() as $row){
    foreach ($row as $column=>$value){
        echo "$column: $value";
    }
}

Might be less confusing for him?




Theme © iAndrew 2016 - Forum software by © MyBB