Jaynesh Posted July 11, 2011 Share Posted July 11, 2011 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>; } Quote Link to comment https://forums.phpfreaks.com/topic/241733-different-colour-depending-on-column-data/ Share on other sites More sharing options...
freelance84 Posted July 11, 2011 Share Posted July 11, 2011 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; } Quote Link to comment https://forums.phpfreaks.com/topic/241733-different-colour-depending-on-column-data/#findComment-1241539 Share on other sites More sharing options...
Jaynesh Posted July 11, 2011 Author Share Posted July 11, 2011 Hello the up and down columns are not part of my query because my query is all linked with joins. How do I put those two columns in my query just for this? Quote Link to comment https://forums.phpfreaks.com/topic/241733-different-colour-depending-on-column-data/#findComment-1241557 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.