tj71587 Posted October 14, 2007 Share Posted October 14, 2007 Hey everyone, this is a piece of the php code I'm making. I want every other row to come out a different color, but the problem is since I've implemented this code, I have been receiving double output. I think I pretty much understand why that is happening, but how is the fix? Thanks $query .= " ORDER BY h.ticketno DESC"; $result = mysql_query($query); $countvar = 0; while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $ticketno=$r["ticketno"]; $connect=$r["connect"]; $date=$r["date"]; $rmnum=$r["rmnum"]; $problem=$r["problem"]; $resolution=$r["resolution"]; $connected=$r["connected"]; if ($countvar % 2 <> 0) { //display the row echo "<tr>"; echo "<td class = \"everyother\">"; echo $ticketno; echo "</td>"; echo "<td class = \"everyother\">"; echo $connect; echo "</td>"; echo "<td class = \"everyother\">"; echo $date; echo "</td>"; echo "<td class = \"everyother\">"; echo $rmnum; echo "</td>"; echo "<td class = \"everyother\">"; echo $problem; echo "</td>"; echo "<td class = \"everyother\">"; echo $resolution; echo "</td>"; echo "<td class = \"everyother\">"; echo $connected; echo "</td>"; echo "</tr>"; $countvar = $countvar + 1; } if ($countvar % 2 == 0) { //display the row echo "<tr>"; echo "<td>"; echo $ticketno; echo "</td>"; echo "<td>"; echo $connect; echo "</td>"; echo "<td>"; echo $date; echo "</td>"; echo "<td>"; echo $rmnum; echo "</td>"; echo "<td>"; echo $problem; echo "</td>"; echo "<td>"; echo $resolution; echo "</td>"; echo "<td>"; echo $connected; echo "</td>"; echo "</tr>"; $countvar = $countvar + 1; } } I have since figured the error out, I needed an else if and not an if for the second condition. Link to comment https://forums.phpfreaks.com/topic/73156-solved-double-output/ Share on other sites More sharing options...
kratsg Posted October 14, 2007 Share Posted October 14, 2007 That's a lotta unneeded code. Try this. $query .= " ORDER BY h.ticketno DESC"; $result = mysql_query($query); $countvar = 0; $rowcounter = 2; while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $ticketno=$r["ticketno"]; $connect=$r["connect"]; $date=$r["date"]; $rmnum=$r["rmnum"]; $problem=$r["problem"]; $resolution=$r["resolution"]; $connected=$r["connected"]; if($rowcounter % 2){$class = " class = \"everyother\"";} else {$class = null;} { //display the row echo "<tr>"; echo "<td$class>"; echo $ticketno; echo "</td>"; echo "<td$class>"; echo $connect; echo "</td>"; echo "<td$class>"; echo $date; echo "</td>"; echo "<td$class>"; echo $rmnum; echo "</td>"; echo "<td$class>"; echo $problem; echo "</td>"; echo "<td$class>"; echo $resolution; echo "</td>"; echo "<td$class>"; echo $connected; echo "</td>"; echo "</tr>"; $rowcounter++; } } Link to comment https://forums.phpfreaks.com/topic/73156-solved-double-output/#findComment-369006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.