The function "render_table" is one I got from someone else, but it doesn't seem to work. I have entered a simple array to test it and I get this error: Warning: Invalid argument supplied for foreach(). I have marked the line in which this occurs.
I don't have the experience to know exactly what is causing the error. Please gander at this and see if the error or errors are apparent.
Thanks!
<?php
$data = array("a" => "January", "b" => "February", "c" => "March" );
render_table ( $data ) ;
echo $html ;
//===========================================
function render_table ( $data )
{
$html = '<table>';
$tr = array ();
foreach ( array_keys ( $data ) as $key )
{
$tr [] = '<th>' . htmlspecialchars($key) . '</th>';
}
$html .= "\n" . '<thead>' . "\n" . '<tr>' . "\n" . implode ( "\n", $tr ) . '</tr>' . '</thead>';
$tbody = array ();
foreach ( $data as $row )
{
$tr = array ();
foreach ( $row as $value ) // < ERROR HERE !!
{
$tr [] = '<td>' . htmlspecialchars ( $value ) . '</td>';
}
$tbody[] = '<tr>' . "\n" . implode ( "\n", $tr ) . '</tr>';
}
$html .= "\n" . '<tbody>' . "\n" . implode ( "\n", $tbody ) . '</tbody>';
$html .= '</table>';
return $html;
}
?>