Welcome Guest, Not a member yet? Register   Sign In
Display query results
#1

[eluser]Unknown[/eluser]
If I do a SELECT ALL and loop, what's the best way to not have to manually enter ever field name to display?

foreach ($query->result() as $row)
{
echo $row->id......
#2

[eluser]NotDior[/eluser]
Perhaps try an array. For instance:

Code:
foreach ($query->result_array() as $sValue=>$aRow) {

print_r($aRow)
}

I'd have to know more of what exactly your trying to get, but that's what I'd do given the information you posted.
#3

[eluser]Unknown[/eluser]
Just so I don't have to type out field names to loop when I'm actually selecting all the data in a table.
#4

[eluser]Samus[/eluser]
Like this?

Code:
foreach ($query->result_array() as $index => $value)
{
echo $index . ' : ' . $value;
}
#5

[eluser]pickupman[/eluser]
Using the [url="http://ellislab.com/codeigniter/user-guide/libraries/table.html"]HTML Table[/url] class, you can generate a table from a result object. Column headers will be the field names.
Code:
$this->table->generate();
Quote:Returns a string containing the generated table. Accepts an optional parameter which can be an array or a database result object.
#6

[eluser]NotDior[/eluser]
Moka - I'd really have to know more of what you are trying to do. If your looking to get the headers (column names from your DB) then I'd check out what pickupman had to say.





Theme © iAndrew 2016 - Forum software by © MyBB