Welcome Guest, Not a member yet? Register   Sign In
How to output unknown field names in result()
#1

[eluser]Richard Testani[/eluser]
I have a situation where I may not know the field names of the rows returned from database query.
How can output these dynamically without having to know the names of the fields?
Is there a way to go through the field names in a result?

Thanks
Rich
#2

[eluser]skunkbad[/eluser]
If you make the result an array, you can always loop through it using foreach
Code:
$returned_data = $query->row_array();
foreach ($returned_data as $rd){
   echo $rd . '<br />';
}
#3

[eluser]Colin Williams[/eluser]
.. and the keys will be the name of the field, in most situations

Code:
$returned_data = $query->row_array();
foreach ($returned_data as $name => $value){
   echo "<strong>$name:</strong> $value<br/>";
}
#4

[eluser]Richard Testani[/eluser]
Yes! This is what I needed - thanks!




Theme © iAndrew 2016 - Forum software by © MyBB