这次我在将值传递到我已经创建的html表时遇到了一些问题。
到目前为止,这是我的代码:
<table id="FinalTable">
<tr>
<td align="center">FECHA</td>
<th colspan="12" align="center">EVENTOS</th>
</tr>
<tr>
<th></th>
<td align="center">HORA INICIO</td>
<td align="center">SUMMARY</td>
<td align="center">DESCRIPTION</td>
<td align="center">LOCATION</td>
<td align="center">CREATED</td>
<td align="center">CREATOR_EMAIL</td>
<td align="center">STARTDATE</td>
<td align="center">START_DATE</td>
<td align="center">START_DATETIME</td>
<td align="center">START_TIMEZONE</td>
<td align="center">END_DATE</td>
<td align="center">END_DATETIME</td>
<td align="center">END_TIMEZONE</td>
</tr>
<tr>
<td align="center">(First date and so on)</td>
<td align="center">(Events detalized)</td>
</tr>
</table>
<br>
<script type="text/javascript" language="javascript">
document.write("<br><br><br>It's the end of the world as we know it!</br> </br></br>");
var ar = <?php echo json_encode($newarray) ?>;
for (var i = 0; i < ar.length; i++) {
for (var j = 0; j < ar[i]['Eventos'].length; j++) {
if(ar[i]['Eventos'][j].isArray !== 'undefined'){
document.write(
'<td><tr> ' + "fecha_inicio" + ' ' + ar[i]['Eventos'][j]['fecha_inicio'] + '</tr></td>' +
' ' + "hora_inicio" + ' ' + ar[i]['Eventos'][j]['hora_inicio'] +
' ' + "summary" + ' ' + ar[i]['Eventos'][j]['summary'] +
' ' + "description" + ' ' + ar[i]['Eventos'][j]['description'] +
' ' + "location" + ' ' + ar[i]['Eventos'][j]['location'] +
' ' + "created" + ' ' + ar[i]['Eventos'][j]['created'] +
' ' + "creator_email" + ' ' + ar[i]['Eventos'][j]['creator_email'] +
' ' + "startdate" + ' ' + ar[i]['Eventos'][j]['startdate'] +
' ' + "start_date" + ' ' + ar[i]['Eventos'][j]['start_date'] +
' ' + "start_datetime" + ' ' + ar[i]['Eventos'][j]['start_datetime'] +
' ' + "start_timezone" + ' ' + ar[i]['Eventos'][j]['start_timezone'] +
' ' + "end_date" + ' ' + ar[i]['Eventos'][j]['end_date'] +
' ' + "end_datetime" + ' ' + ar[i]['Eventos'][j]['end_datetime'] +
' ' + "end_timezone" + ' ' + ar[i]['Eventos'][j]['end_timezone'])
}
}
}
所以,基本上我不知道如何将document.write
之后的所有值插入到表的de字段中。
可以请有人帮助我吗?
非常感谢最亲爱的堆货机!
答案 0 :(得分:1)
表格行必须在</table>
之前。 <td>
需要在<tr>
内,但你可以反过来。<td>
很多你的价值观根本不在<table id="FinalTable">
<tr>
<td align="center">FECHA</td>
<th colspan="12" align="center">EVENTOS</th>
</tr>
<tr>
<th></th>
<td align="center">HORA INICIO</td>
<td align="center">SUMMARY</td>
<td align="center">DESCRIPTION</td>
<td align="center">LOCATION</td>
<td align="center">CREATED</td>
<td align="center">CREATOR_EMAIL</td>
<td align="center">STARTDATE</td>
<td align="center">START_DATE</td>
<td align="center">START_DATETIME</td>
<td align="center">START_TIMEZONE</td>
<td align="center">END_DATE</td>
<td align="center">END_DATETIME</td>
<td align="center">END_TIMEZONE</td>
</tr>
<tr>
<td align="center">(First date and so on)</td>
<td align="center">(Events detalized)</td>
</tr>
<?php
foreach ($newarray as $el) {
foreach ($el['Eventos'] as $event) {
if (is_array($event)) {
echo "<tr>";
echo "<td>{$event['fecha_inicio']}</td>";
echo "<td>{$event['hora_inicio']}</td>";
// repeat for all fields in $event
echo "</tr>";
}
}
}
?>
</table>
。
你应该用PHP完成整个事情。
{{1}}