Jump to content

WHAT THE HELL IS WRONG HERE!!


Orionsbelter

Recommended Posts

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?

 

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

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.