1

I have the below code and I know both the $headers and the $html have values stored in them as i can echo them out. I can also set the 'header' => in the theme function to be either $header or $html and it will display the data.

However when I add in 'rows' =>, no data is displayed.

Can anyone see why?

function emnies_ad_hoc_query_exporter_get_html_formatted_ad_hoc_query_responses($obj_response) {
  $str_current_country = '';

  foreach ($obj_response as $response) {
    if ($str_current_country != $response->country) {
      $str_current_country = $response->country;
      $html = emnies_ad_hoc_query_exporter_get_country_row($str_current_country, $obj_response);
    }
  }
  $header = array('Country', 'Wider Dissemination', 'Responses'); 
  $output = theme('table', array(
    'header' => $header, 
    'rows' => $html
  ));
  return $output;
}



function emnies_ad_hoc_query_exporter_get_country_row($str_current_country, $obj_response) {
  $rows = array();
  $i = 0;
  foreach ($obj_response as $response) {
    if ($str_current_country == $response->country) {
      if ($i == 0) {
        $rows[] = $str_current_country;
        $rows[] = $response->wider_dissemination;
      }
      $i = $i + 1;
      $rows[] = $response->response;
    }
  }
  return $rows;
}
1
  • What does $response->response return? Also what exactly are you trying to do with your function?
    – iLLin
    Commented Apr 13, 2015 at 22:38

1 Answer 1

0

Try looking at it this way. From looking at your $header, you are looking for 3 columns?

foreach ($obj_response as $response) {
if ($str_current_country == $response->country) {
  $rows[] = array($str_current_country, $response->wider_dissemination, $response->response);
}

EDIT

// Test Output
$header = array(t('Country'), t('Wider Dissemination'), t('Responses'));
$rows = array();
$rows[] = array('US', 'Extremely Wide', 'Response');
print theme('table', array('header' => $header, 'rows' => $rows));

The test works for me. Maybe something in your response value is messing with it?

3
  • Thanks @iLLin, However even if I use '$header = array('Country', 'Wider Dissemination'); $html = array(' Answer 1', 'Answer 2'); $output = theme('table', array('rows' => $header,'rows' => $html)); return $output;' It still doesn't work. I just get the error "Warning: Invalid argument supplied for foreach() in include() (line 114 of sites/all/themes/ec_resp/templates/global/table.tpl.php)"
    – James
    Commented Apr 14, 2015 at 8:30
  • Edited the response.
    – iLLin
    Commented Apr 14, 2015 at 12:25
  • Also, from your comment, you have rows listed twice in your theme('table').
    – iLLin
    Commented Apr 14, 2015 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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