I've been trying to solve this for straight hours, and admittedly my knowledge of PHP is extremely limited, as this is not my code (I have hired a programmer). Basically, I'm trying to have alternating table row colors in a table on my page, with the lightest color coming first, then the darker one, then the lighter one, and it keeps repeating.
But, if there are an even number of dogs being displayed, the darker color comes first. If there's an odd number, everything goes as it should.
I've used multiple tutorials on this, but when the alternating table colors show up correctly, it just shows 5 or 6 repeats of the same dog. So I still haven't found a solution to this.
The code:
echo ("<table style='border-style:solid; border-width:2px; border-color:#b7996d;' cellspacing='3' cellpadding='3' width='85%'>
<tr><td bgcolor='#644a24' colspan='4' align='center'>
<font color='d1ead0'><b>Dogs in Kennel</b></font>
</td></tr>
<tr><td bgcolor='#afdbad' width='31%' align='center'>
<b>Name</b>
</td>
<td bgcolor='#afdbad' width='19%' align='center'>
<b>Sex</b>
</td>
<td bgcolor='#afdbad' width='28%' align='center'>
<b>Breed</b>
</td>
<td bgcolor='#afdbad' width='22%' align='center'>
<b>Age</b>
</td></tr>");
$query = ("SELECT * FROM dogs WHERE dog_owner='$cani_id' ORDER BY dog_id");
$result2 = mysql_query($query) or die(mysql_error());
$check_dogs = mysql_num_rows($result2);
if ($check_dogs > '0'){
$query = ("SELECT * FROM dogs WHERE dog_owner='$cani_id' ORDER BY dog_id");
$res = mysql_query ($query) or die(mysql_error());
while ($row = mysql_fetch_assoc ($res)){
$dog_id = $row['dog_id'];
$dog_age = $row['dog_age'];
$dog_name = $row['dog_name'];
$dog_nickn = $row['dog_nickn'];
$dog_breed = $row['dog_breed'];
$dog_owner = $row['dog_owner'];
$dog_gender = $row['dog_gender'];
if (!empty($dog_nickn)){
$dog_nickn = ("\"$dog_nickn\"");}
$check_dogs++;
if (is_float($check_dogs/2)){
$rowcolor = ("#c9e9c7");}
if (!is_float($check_dogs/2)){
$rowcolor = ("#e1f2de");}
if (($check_dogs % 2) == 0){
$hai = ("even");}
else {
$hai = ("odd");}
echo ("<tr><td bgcolor='$rowcolor' width='31%' align='center'>
<a href='/dogs.php?id=$dog_id'>$dog_name $dog_nickn</a>
</td>
<td bgcolor='$rowcolor' width='19%' align='center'>
$dog_gender
</td>
<td bgcolor='$rowcolor' width='28%' align='center'>
$dog_breed
</td>
<td bgcolor='$rowcolor' width='22%' align='center'>
$dog_years $year_count $dog_months $month_count
</td></tr>");}}
else {
echo ("<tr><td bgcolor='#e1f2de' colspan='4' align='center'>
<i>There are no dogs in this kennel.</i>
</td></tr>");}
echo ("</table><br>");
Thank you so much in advance to whoever can help me with this!