CodeIgniter Forums
Print the field name, and its value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Print the field name, and its value (/showthread.php?tid=15501)



Print the field name, and its value - El Forum - 02-06-2009

[eluser]gh0st[/eluser]
I have a really big table, and I don't want to be doing:

Code:
print "Name: " . $row->name
print "Age: " . $row->age
print "Salary: " . $row->salary
// ...etc..

I want to do:

Code:
print $field->name;
print $field->value;

// output: name: John
// output: age: 32
// output: salary: 1000
// etc

I've looked at $this->db->field_data() but there is no $this->db->field_value attribute.

Is there a way to do this?


Print the field name, and its value - El Forum - 02-06-2009

[eluser]edwa5823[/eluser]
Will something like this work for you? Either you can print everything in a loop or assign some new variables for each.

Code:
foreach($row as $key => $value) {
   print "$key = $value\n";
}