christa Posted January 2, 2011 Share Posted January 2, 2011 hi all, in my blog (made by me, no wordpress or similar) i would want to change the color of comments written by author of article My code is: $sql = "SELECT author WHERE art_id=..."; //print all comments... while ($row = mysql_fetch_array($result)) { if ($_SESSION['ID_user'] == $sql['ID_user'] ) { $color = "#FFFFFF"; } else { $color = "#FF0000"; } echo '<div id="comment" style="background-color: ' . $color . '">post</div>'; } but the code above print all FFFFFF or all FF0000 Where it is wrong? thanks Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/ Share on other sites More sharing options...
Pikachu2000 Posted January 2, 2011 Share Posted January 2, 2011 I believe that $sql['ID_user'] is undefined. It should be $row['ID_user'], no? Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1153844 Share on other sites More sharing options...
christa Posted January 2, 2011 Author Share Posted January 2, 2011 here the complete code: //print all comments... while ($row = mysql_fetch_array($result)) { $sql_user = mysql_query("SELECT u.IDuser FROM users u JOIN articles a ON a.IDuser=u.IDuser AND a.IDart=$_GET['IDart'] WHERE u.IDuser=" . $_SESSION['IDuser'] . ""); $row2 = mysql_fetch_array($sql_user); if ($_SESSION['IDuser'] == $row2['IDuser'] ) { $color = "#FFFFFF"; } else { $color = "#FF0000"; } echo '<div id="comment" style="background-color: ' . $color . '">post</div>'; } Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1153849 Share on other sites More sharing options...
Pikachu2000 Posted January 2, 2011 Share Posted January 2, 2011 That isn't the same code that's in your first post. Which one is the code that's actually being used? Without the actual code that's causing the actual problem, there's no point even looking at it. Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1153853 Share on other sites More sharing options...
PFMaBiSmAd Posted January 2, 2011 Share Posted January 2, 2011 There's also no point in executing the same exact query over and over inside of a loop. The result will be exactly the same each time the query is executed. Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1153855 Share on other sites More sharing options...
christa Posted January 2, 2011 Author Share Posted January 2, 2011 the actual code is my second. Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1153857 Share on other sites More sharing options...
christa Posted January 3, 2011 Author Share Posted January 3, 2011 some suggests? Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1154286 Share on other sites More sharing options...
BlueSkyIS Posted January 3, 2011 Share Posted January 3, 2011 is this ever true? echo the values and see. $_SESSION['IDuser'] == $row2['IDuser'] Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1154290 Share on other sites More sharing options...
christa Posted January 3, 2011 Author Share Posted January 3, 2011 yes, the 2 values are comparated and matched when the user is logged and he is the author of the article Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1154329 Share on other sites More sharing options...
BlueSkyIS Posted January 3, 2011 Share Posted January 3, 2011 so, are the conditions ALWAYS true? -----> echo the values and see. <----- Quote Link to comment https://forums.phpfreaks.com/topic/223196-change-post-author-color/#findComment-1154373 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.