Orionsbelter Posted March 8, 2010 Share Posted March 8, 2010 Lol really getting annoyed now look at this: $i = 0; $mailSQL = mysql_query("SELECT * FROM `mail` WHERE `To`='$username'"); $num=mysql_num_rows($mailSQL); while ($fetchMail=mysql_fetch_object($mailSQL)) { $bgclass = ($i % 2)?'even':'odd'; $id=$i; if($id!=="$num"){$bot="";}else{$bot="bottom";} if($fetchMail->Read=="0"){$imgIcon="<img src=\"../images/icons/unread.gif\" width=\"20\" height=\"15\" alt=\"Unread\" title=\"Unread\" />";}else{$imgIcon="<img src=\"../images/icons/read.gif\" width=\"20\" height=\"15\" alt=\"Read\" title=\"Read\" />";} $from="$fetchMail->From"; $subject="$fetchMail->Subject"; $date="$fetchMail->Time, $fetchMail->Day $fetchMail->Month $fetchMail->Year"; echo "<tr> <td width=\"30\" class=\"".$bgclass."".$bot."\">$imgIcon</td> <td width=\"168\" class=\"".$bgclass."2".$bot."\"><a href=\"../profile.php?user=$from\">$from</a></td> <td class=\"".$bgclass."3".$bot."\"><a href=\"#\">$subject</a></td> <td class=\"".$bgclass."3".$bot."\">$date $bot<</td> <td class=\"".$bgclass."4".$bot."\"><img src=\"../images/icons/deleteMa.png\" width=\"15\" height=\"15\" alt=\"Delete\" /></td> </tr>"; $i++; } What the colour change on each row works with odd and even CSS classes but a second bottom class is assigned to the last row i've tried to get the total rows then matched with with the $i in order to identify the last row but it still doesn't work anyhelp? Quote Link to comment https://forums.phpfreaks.com/topic/194557-what-the-hell-is-wrong-here/ Share on other sites More sharing options...
schilly Posted March 9, 2010 Share Posted March 9, 2010 $i starts at 0 so you will never reach $num. Quote Link to comment https://forums.phpfreaks.com/topic/194557-what-the-hell-is-wrong-here/#findComment-1023275 Share on other sites More sharing options...
Zane Posted March 9, 2010 Share Posted March 9, 2010 Don't you think it's a little bit.. no.. REALLY redundant to use the variable $bgclass over and over and over again? When you're just gonna use it to distinguish whether or not that particular element is nested within an.. odd... or even element. You're going about it all the wrong way. You know you're doing it the right way when you only have to use that variable ONCE For example YOUR CODE echo " $imgIcon $from $subject $date $bot "; It's very obvious to me that the only differences that appear. (whether odd or even) is the $bot variable .. and a number before that. And judging by your logic before all this.. $bot is either gonna be nothing at all.. OR "bottom". So assuming this is the "last" post.. your class will look like this when echoed If you notice.. the class name is odd3bottom.. with no spaces. That means you need a class in your stylesheet named just as such. Which I'd assume you don't. The simplest fix to all this would be to separate each with spaces so your class name is odd 3 bottom. That way is has 3 classes. BUT, let's not stop there! Why even put odd in every single td element when you could just as easily put it in the TR tag instead? Better yet... why even put the "bottom" class name either? In short.. change your code to something a little more like this $i = 0; $mailSQL = mysql_query("SELECT * FROM `mail` WHERE `To`='$username'"); $num=mysql_num_rows($mailSQL); while ($fetchMail=mysql_fetch_object($mailSQL)) { $bgclass = ($i % 2) ?'even':'odd'; $bgclass = ($i == $num) ? $bgclass : 'bottom'; ////// Use just one variable for your classes if($fetchMail->Read=="0"){$imgIcon="";}else{$imgIcon="";} $from="$fetchMail->From"; $subject="$fetchMail->Subject"; $date="$fetchMail->Time, $fetchMail->Day $fetchMail->Month $fetchMail->Year"; echo " $imgIcon $from $subject $date $bot "; $i++; } Of course.. this means you'll also have to edit your stylesheet accordingly.. Quote Link to comment https://forums.phpfreaks.com/topic/194557-what-the-hell-is-wrong-here/#findComment-1023284 Share on other sites More sharing options...
Orionsbelter Posted March 9, 2010 Author Share Posted March 9, 2010 Hello thank you both, and i can not but the odd or even within the TR tags as each column in the table has a different class style such as the first column is odd the second is odd 2 the third and fourth is odd3 and the fifth is odd4. Same with the even. so each column is different. Quote Link to comment https://forums.phpfreaks.com/topic/194557-what-the-hell-is-wrong-here/#findComment-1023648 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.