Jump to content

[SOLVED] Double Output


tj71587

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.