0

I'm having trouble getting the array to show up like this.

$womensLevels = array('WEXHIB' => 'Exhib Camp/Test', 'WLEVEL01' => 'Level 1', 'WLEVEL02' => 'Level 2', 'WLEVEL03' => 'Level 3', 'WLEVEL04' => 'Level 4', 'WLEVEL05' => 'Level 5', 'WLEVEL06' => 'Level 6', 'WLEVEL07' => 'Level 7', 'WLEVEL08' => 'Level 8', 'WLEVEL09' => 'Level 9', 'WLEVEL10' => 'Level 10', 'WOPEN' => 'Open', 'WPREPOPT' => 'Prep OPT', 'WTOPS' => 'TOPS');

It ends up like this when I do my query and drop it into my view (html). I just want the Code key and the Description key to show up with there values.

[0]=>
  array(2) {
    ["Code"]=>
    string(4) "IW01"
    ["Description"]=>
    string(13) "Intro Level 1"
  }
  [1]=>
  array(2) {
    ["Code"]=>
    string(4) "IW02"
    ["Description"]=>
    string(13) "Intro Level 2"
  }
  [2]=>
  array(2) {
    ["Code"]=>
    string(4) "IW03"
    ["Description"]=>
    string(13) "Intro Level 3"
  }

Here are my queries.

This is where the array comes from.

$womensLevels = sprintf("SELECT `Code`,`Description` FROM `mb_ro_type_codes` where `Program` = '%s'", $sanction->Program);

$smarty->assign('womensLevels', $db->query($womensLevels));

Here is my html I put my variables into from my controller.

{html_checkboxes name='code' options=$womensLevels selected=$checked}

I suppose what I am trying to ask is how to breakdown my array?

1 Answer 1

2

You have to loop the db query results and build another array in the format you want, instead of directly passing the query results to the template. Something like this:

$results = $db->query($womensLevels);
$formattedResults = array();
foreach($results as $result) {
    formattedResults[$result['Code']] = $result['Description'];
}
$smarty->assign('womensLevels', $formattedResults);
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.