Robert Dickey Robert Dickey - 1 month ago 8
JSON Question

Trouble creating table with Json_Decode

I am working with another company's AP and they return a set of data to me via XML. I am attempting to take that xml data, and turn it into an HTML table. The XML decodes perfectly, and I can display the

$result
in a non-table format, but when I try to format it, I receive a server error..I am at my wits end here.

Here is my code (bottom half)

$array = json_decode(json_encode((array)simplexml_load_string($result)),1);

$array_user=$array['user'];

$tab='<table border="1" width="400">';
for ($j=1; $j< count($array_user) ; $j++) {

$tab.='<tr>';
$tab.='<td>'.$array_user[$j]['id'].'</td>;
$tab.='<td>'.$array_user[$j]['login'].'</td>;
$tab.='<td>'.$array_user[$j]['mail'].'</td>;
$tab.='<td>'.$array_user[$j]['date'].'</td>;
$tab.='</tr>';
}

$tab.='</table>';

echo $tab;
?>


Does anyone with experience in this area know why or see why I am receiving a generic error? Any help would be greatly appreciated.

Answer

You missed to close all string literals.

So for example the following line:

$tab.='<td>'.$array_user[$j]['id'].'</td>;

must look like this:

$tab.='<td>'.$array_user[$j]['id'].'</td>'; // <-- note the closing '
Comments