Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Iterating through an associative array from SQL query

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37421
    D3mon
    Member

    Hi guys,

    I have an associative array (arrInfo) that I can’t seem to get the data from. Here’s the print_r output as an example:

    Array ( [0] => Array ( [label_text] => Area of coverage [data] => 160 m� ) [1] => Array ( [label_text] => Dimensions [data] => 352 x 277 x 112 (mm) ) [2] => Array ( [label_text] => Finish [data] => Aluminium ) [3] => Array ( [label_text] => Lamp [data] => EcoLite energy saving 13 watt (�2) ) [4] => Array ( [label_text] => Lead length [data] => 1.1m ) [5] => Array ( [label_text] => Mounting [data] => Wall mount, ceiling suspend or free stand ) [6] => Array ( [label_text] => Power input [data] => 230Vac 50Hz (standard UK mains supply) ) [7] => Array ( [label_text] => Warranty period [data] => 1 year ) )

    I need to iterate this array to create a HTML definition list (DL) with the DD term as the [label_text] and the DT as the [data value] for each row.

    The code I have right now is:

    foreach($arrInfo as $row) {
    echo ”.$row.”.$row.”;
    }

    but it only returns the last row of the array (arrInfo)?

    #100283
    D3mon
    Member

    OK. Scratch that – it was working fine. I was building an output string instead of echo’ing and discovered that I was overwriting the string with each loop! DUH. :)

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.