我有一个使用静态<table>手动更新的自定义电视时间表。每个<tr>有5个<td>子级,每个子级按顺序包含以下内容之一:日期、时间、比赛、比赛和电视频道。
<table>
<tr><th>DATE</th><th>TIME</th><th>COMPETITION</th><th>MATCH</th><th>CHANNEL</th></tr>
<tr class="comp-1 ch-1">
<td>October 17</td>
<td>5 PM</td>
<td></td>
<td>Team Alpha v Team Bravo</td>
<td></td>
</tr>
</table>我有以下PHP Array
<?php
$comps = [
'comp-1' => 'Tug-of-War',
'comp-2' => 'Tag Rugby',
'comp-3' => 'Handball',
'comp-4' => 'The Gauntlet',
];
$channels = [
'ch-1' => 'Channel 1',
'ch-2' => 'Channel 2',
'ch-3' => 'Channel 3',
'ch-4' => 'Channel 4',
];
?>我想做的是让空的<td>单元格根据它们的<tr>父单元的class属性值自动填充。我需要做这一点在PHP的XML,SEO和OGP的目的。以前,它是使用jQuery完成的,但是使用Google's Rich Snippets Testing Tool的测试显示,当页面加载时,空的<td>单元被读取为空。
如果有人能帮助我如何获得这一点,我将不胜感激!
发布于 2013-10-18 08:07:34
在每一行中分配一个变量(希望在您使用的foreach语句中...)以对应于每个数组中的数字,然后在每个循环结束时递增它们。
$comp_row_id = 1;
$ch_row_id = 1;
$competition = $comps['comp-' . $comp_row_id]; // Tug-of-War
$channel = $comps['ch-' . $ch_row_id]; // Channel 1
$comp_row_id++;
$ch_row_id++;如果$comp_row_id和$ch_row_id总是相同的,只需将这些变量组合成一个名为$i或类似的变量,以保持一致性。
https://stackoverflow.com/questions/19439338
复制相似问题