0

Without using echo, how do I get the $report array of records to populate this html table?

The first row $report[0] shows up fine but I'm not sure how to get it loop through the table and automatically display the other rows.

$report = get_field('maths_month_report');
$report1 = $report[0];
$report2 = implode('</td><td>', $report1);

if (in_array('Maths', $subjecttitle)) {
return '

<table width="100%" id="report">
<tr>

<th width="10%">Month</th>
<th width="10%">Progress</th>
<th width="10%">Well-being</th>
<th width="35%">Remarks</th>
<th width="35%">Target</th>
</tr>
<tr> 
<td>'. $report2 .'</td>
</tr>
</table>

';
}
1
  • you need to use PHP loop algorithm. You can use foreach. Ex: foreach( $report as $re ){ // $report1, $report2, in_array etc codes // $html .= 'Your table code'; } Commented Jan 4, 2014 at 20:23

1 Answer 1

1
$str = '<table width="100%" id="report">';
$str .= '<tr>
    <th width="10%">Month</th>
    <th width="10%">Progress</th>
    <th width="10%">Well-being</th>
    <th width="35%">Remarks</th>
    <th width="35%">Target</th>
    </tr>';
foreach($report as $v){
    $str .= '<tr>
    <td>'. $v['val1'] .'</td>
    <td>'. $v['val2'] .'</td>
    <td>'. $v['val3'] .'</td>
    <td>'. $v['val4'] .'</td>
    <td>'. $v['val5'] .'</td>
    </tr>';
}
$str .= '</table>';

return $str;

i hope it will help you

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so very much. I'm still a bit newb so it took me a while to figure out val1, val2, etc should be the field names for the records. Absolutely fantastic!!!
val1, val2 are field names in associated array.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.