Jump to content

different colour depending on column data


Jaynesh

Recommended Posts

Hello

 

I have three tables

 

users(user id, vote id)

posts(post id, user id, post)

vote(vote id, post id, up, down)

 

This is my while loop.

It outputs all the posts users have made.

each post has a box around it.

 

My div id 'postbox' is stored in a seperate CSS file containing a colour value.

How do I change the colour value depending on data in vote(up, down)

 

while( $i < $row = mysql_fetch_array($query))

  {

  echo "<div id=" . "postbox". ">";

  echo $row['post'];

  echo  "</div>;

  }

How do I change the colour value depending on data in vote(up, down)

What are the possible values for up and the possible values for down?

 

 

 

 

while( $i < $row = mysql_fetch_array($query))

  {

  echo "<div id=" . "postbox". ">";

  echo $row['post'];

  echo  "</div>;

  }

 

Could be:

while( $i < $row = mysql_fetch_array($query))
  {
      if($row['up'] == yes)
         {
            $postboxColor = 'green';
         }
      else{
            $postboxColor = 'red';
            }
echo <<<_END
<div id="postbox $postboxColor">
   $row['post']
</div>
_END;
  }

 

Archived

This topic is now archived and is closed to further replies.

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