Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP while loop to get values from mysql data base if it equals the $i value
    text
    copied!<p>I'm trying to get a value to be inserted into a table on a webpage if the value equals $i.</p> <p>$i starts at a number and decreases every loop. i can get it to work but it outputs multiple lines for each $i equivalent to the results in the table</p> <p>I've reworked the code using everyones feedback to get this.</p> <pre><code>Echo "&lt;tr&gt;&lt;th colspan='3'&gt;&lt;center&gt;$rackname&lt;/th&gt; &lt;/tr&gt;" ; for ($i=$RUtotal; $i &gt; 0; $i--) { echo" &lt;tr class='rackbg'&gt;&lt;td class='i'&gt;&lt;center&gt;$i&lt;/td&gt;" ; $sql1 = "SELECT racks.rackID, racks.rackname, devices.deviceID, devices.deviceName, racks.rackRU, devices.deviceRU, devices.RUcount FROM racks LEFT JOIN devices ON racks.rackID = devices.rackID WHERE devices.rackID = '$rackID'"; $query1 = mysql_query($sql1); while ($row = mysql_fetch_assoc($query1)) { $deviceru = $row['deviceRU']; $deviceID = $row['deviceID']; $device = $row['deviceName']; $deviceRUC = $row['RUcount']; if ($deviceru == $i) { echo '&lt;td class="device" rowspan='.$deviceRUC.'&gt;&lt;a onclick=window.location="/devices.php?id='.$deviceID.'"&gt;'.$device.'&lt;/a&gt;&lt;/td&gt;&lt;td rowspan='.$deviceRUC.'&gt;&lt;/td&gt;&lt;/tr&gt;'; } else { ; } } } Echo "&lt;tr class='rackb'&gt;&lt;th colspan='3'&gt;a&lt;/th&gt;&lt;/tr&gt; " ; </code></pre> <p>This works to a degree (picture1) but when i add echo "" to the else statement it displays all wrong. (picture 2)</p> <p>Any help would be greatly appreciated</p> <p>Picture1 - <a href="http://imageshack.us/photo/my-images/263/examplewq.png/" rel="nofollow">http://imageshack.us/photo/my-images/263/examplewq.png/</a></p> <p>Picture2 - <a href="http://imageshack.us/photo/my-images/269/example2jp.png/" rel="nofollow">http://imageshack.us/photo/my-images/269/example2jp.png/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload