saint
saint

Reputation: 268

displaying a comparison table using 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

Upvotes: 0

Views: 844

Answers (1)

Nouphal.M
Nouphal.M

Reputation: 6344

Try altering your inner loop's condition like the following

for ($j=$i+1; $j <= (sizeOf($myArray)); $j++){

Upvotes: 1

Related Questions