Grow your CSS skills. Land your dream job.

Iterating through an associative array from SQL query

  • # March 30, 2012 at 5:44 am

    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)?

    # March 30, 2012 at 5:56 am

    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. :)

    # March 31, 2012 at 1:53 am

    lol, I was going to tell you that but you figured it out! Good work ;)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".