CodeIgniter Forums
Looping through row columns values in a row? - 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: Looping through row columns values in a row? (/showthread.php?tid=28593)



Looping through row columns values in a row? - El Forum - 03-16-2010

[eluser]Stephen G[/eluser]
Hi Tongue
I am new to code ignitor, and PHP :bug: :wow:

I am returning a set of results and loop through the results to print out a name value pair...
But i can not figure out what the best way to approach this? :red:

Here is my code... I want to do something like this??...


Code:
$this->db->where('id_fields', $row->id_forms_fields);
$data['field'] = $this->db->get('fields');

foreach($data['field']->result() as $field) {

  if($field->tagname == 'input') {
     foreach($field->result() as $item) {
        echo '"' $item['column'] . '" : "' $item['value'] . '"';        
     }
  }

This is what my table looks like

Code:
____________________________________________________________________________________
ID | TAGNAME |  TYPE | CLASS | ID               | VALUE | TABINDEX | NAME          |
=======================================================
1    | INPUT       | Text    |  text   | first_name | NULL    |   1              | first_name |
=======================================================
2   | INPUT       | Text    |  text   | last_name  | NULL    |   2              | last_name |
=======================================================

Is there a way to loop through each item in a row and print out the column name and value in either codeignitor or PHP?

Sincerely,
Steve :cheese:


Looping through row columns values in a row? - El Forum - 03-16-2010

[eluser]Mareshal[/eluser]
[quote author="Stephen G" date="1268747447"]Hi Tongue
I am new to code ignitor, and PHP[/quote]

Off topic: I don't think you are working with CodeIGNITOR, is CodeIgniter in my knowledge.
On topic: If you are new to PHP, don't work with CodeIgniter from start. Better try to make easy tasks using simple PHP, see how they work, then move to CI. I had 2 years PHP experience when I started CI.

To loop between columns, try this: http://ellislab.com/codeigniter/user-guide/database/forge.html