I have this code
while ($row = mysql_fetch_assoc($wynik)) {
    echo '<tr class="ad">  ';
    foreach ($row as $key => $value) {
        if ($value != null){
            if ($value<=1){
                $wymiar = $key."x".$first;
                $wynik3 = mysql_query("SELECT * FROM `".$nazwa2."` where `tak` = '".$wymiar."' ");
                while ($row = mysql_fetch_array($wynik3)) {
                    if ($row["tak"] == $wymiar){
                        echo $row["id"];
                        echo '<td width=25px; style="background-color: red; border-color: blue;" border="1"><p style="display:block;">'.$key.'x'.$first.'</p></td>';
                    }
                    unset($wymiar);
                }  
                echo '<td width=25px; style="background-color: green; border-color: blue;" border="1"><p style="display:block;">'.$key.'x'.$first.'</p></td>';
            } else {
                echo '<td width=25px; style="background-color: yellow; border-color: blue;" border="1">'.$value."</td>";
                $first = $value;
            }
        } else {
            echo '<td width=25px; style="background-color: magenta; border-color: blue;" border="1">'.$value."</td>";
        }
    } echo "</tr>";
}
How to correctly use "if ... else" statement, Now is something wrong. It adds a red cell but also leaves a record with the green cell and moves the entire row
 
     
     
    