dopii22884 2013-12-07 02:42
浏览 18
已采纳

使用php显示比较表

I am trying to output a table which compares two elements at a time with a radio button at the end of each row. I have created a loop with iterates through the whole table and jumps the next 'table' if the inner loop has finished executed. and an inner loop which compares the elements. The problem I am having is, if two elements have been compared in the previous set, it should not be repeated in any other sets. Please refer to the image I have below.

I have tried different ways but here is the code I have:

for ($i=0; $i < (sizeOf ($myArray)); $i++){ //loop through the whole table body 
    $currentObs = $myArray[$i]['ObstacleDescription']; //set pointer to my current obstacle value
    $x = 0;
    for ($j=1; $j <= (sizeOf($myArray)-1); $j++){ //loop through the inner table
        $next = $myArray[$j]['ObstacleDescription'];
        $or = " or ";
        if (!($currentObs == $next)){
        ?>
            <tr id="<?php echo $myArray[$i]['ComplianceID']; ?>">
            <td valign='center'> <?php echo $x+1; ?> </td>
            <?php $x++; ?>
            <td>
            <?php echo 
            "<input type='radio' name='op[$j]' value='0' class='myradio'>"." ".$currentObs
            ?>
                        </td>

             <td><?php echo
             $or." "."<input type='radio' name='op[$j]' value='1' class='myradio'>"." ".$next;
             ?>
             </td>
             <td><small>
             <?php echo  " 1 "."<input type='radio' name='Intense[$j]' value='1' class='myradio'>"; ?>

             </small></td>
             <td><small>
             <?php echo 
             " 2 "."<input type='radio' name='Intense[$j]' value='2' class='myradio'>".
             " 3 "."<input type='radio' name='Intense[$j]' value='3' class='myradio'>".
             " 4 "."<input type='radio' name='Intense[$j]' value='4' class='myradio'>".
             " 5 "."<input type='radio' name='Intense[$j]' value='5' class='myradio'>".
             " 6 "."<input type='radio' name='Intense[$j]' value='6' class='myradio'>".
             " 7 "."<input type='radio' name='Intense[$j]' value='7' class='myradio'>".
             " 8 "."<input type='radio' name='Intense[$j]' value='8' class='myradio'>".
             " 9 "."<input type='radio' name='Intense[$j]' value='9' class='myradio'>";
             ?>

             </small></td>
<?php    }
     }
     echo "<tr><td colspan='5'><hr style='border:0; height:0px' /></td></tr>";
     echo "<tr><td colspan='5'><hr style='border:0; height:0px' /></td></tr>";
}
echo "</tr>";
?>

Here is what I have at the moment

But here is what I am trying to achieve: What I want to achieve

  • 写回答

1条回答 默认 最新

  • doukun8944 2013-12-07 04:09
    关注

    Try altering your inner loop's condition like the following

    for ($j=$i+1; $j <= (sizeOf($myArray)); $j++){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据