2013-10-18 54 views
0

我有一个自定义的电视时间表,我手动更新使用静态<table>。每个<tr>有5 <td>儿童,其中每个儿童按以下顺序包含以下内容之一:日期,时间,比赛,比赛和电视频道。PHP:如何填充基于父类属性的HTML元素

<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>单元正被读为空。

如果任何人可以帮助我有关如何实现这一目标的任何想法,我将不胜感激!

回答

0

在每行中分配一个变量(希望在您使用的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或一致性类似。