gurpreet Posted July 19, 2010 Share Posted July 19, 2010 Hey everyone, I have a small problem. I am trying to edit my header so that it will check if there are people on the hitlist. If there are, it will display the number in brackets. I have this so far: <?php $ifhit = "select status from hitlist"; $res = db_execute_return($ifhit); $r = mysql_fetch_assoc($res); if( $r == active) { echo "<span class="txt_2">[url="hitlist.php"][b]Hitlist[/b][/url]</span>"; } else { echo "<span class="txt_1">[url="hitlist.php"]Hitlist[/url]</span>"; ?> The status is either 'active' which means they are on the htilist, or done, which means they have been killed. Also not sure if mysql_fetch_assoc is needed, still learning that stuff. All help is appreciated :) Quote Link to comment Share on other sites More sharing options...
Danny696 Posted July 19, 2010 Share Posted July 19, 2010 if( $r == 'active') { echo'<span class="txt_2">Hitlist</span>'; } else { echo'<span class="txt_1">Hitlist</span>'; } ?> Quote Link to comment Share on other sites More sharing options...
gurpreet Posted July 20, 2010 Author Share Posted July 20, 2010 That doesn't hange it to span class 2, or bold, even though 2 people are on the hitlist. I'm guessing the mysql_fetch_assoc is wrong. What do I have to use for that? Quote Link to comment Share on other sites More sharing options...
LordDan Posted July 21, 2010 Share Posted July 21, 2010 I do not know what source you're using so forgive me if what i am posting is incorrect. If you want to show how many users are on the Hitlist, would a num_rows query not be more suitable? $result = db_execute_return( "SELECT id FROM hitlist WHERE status='active'" ); $count = mysql_num_rows( $result ); $css = ( $count > 0 ) ? 'txt_2' : 'txt_1'; // Sets the class for the span $count = ( $count < 1 ) ? 0 : $count; // Make sure our count is 0 rather than empty. echo '<span class="'. $css .'">[url="hitlist.php"]Hitlist('. $count .')[/url]</span>'; Resulting in: Hitlist(2) OR Hitlist(0) Also, there is no need to add around Hitlist, just add it into the CSS class. .txt_2 a { font-weight: bold; } Hope this helps you out a little, but as stated i am not sure what source you're using, nor would i be familiar with it even if i did. :huh: Good luck! :thumbup: EDIT: Fixed a small mistake.. Quote Link to comment Share on other sites More sharing options...
gurpreet Posted July 21, 2010 Author Share Posted July 21, 2010 I do not know what source you're using so forgive me if what i am posting is incorrect. If you want to show how many users are on the Hitlist, would a num_rows query not be more suitable? $result = db_execute_return( "SELECT id FROM hitlist WHERE status='active'" ); $count = mysql_num_rows( $result ); $css = ( $count > 0 ) ? 'txt_2' : 'txt_1'; // Sets the class for the span $count = ( $count < 1 ) ? 0 : $count; // Make sure our count is 0 rather than empty. echo '<span class="'. $css .'">[url="http://makewebgames.io/hitlist.php"]Hitlist('. $count .')[/url]</span>'; Wow it worked, can't believe it was so simple! Cheers :D Resulting in: Hitlist(2) OR Hitlist(0) Also, there is no need to add around Hitlist, just add it into the CSS class. .txt_2 a { font-weight: bold; } Hope this helps you out a little, but as stated i am not sure what source you're using, nor would i be familiar with it even if i did. :huh: Good luck! :thumbup: EDIT: Fixed a small mistake.. Quote Link to comment Share on other sites More sharing options...
LordDan Posted July 21, 2010 Share Posted July 21, 2010 Wow it worked, can't believe it was so simple! Cheers :D You're Welcome. ^^ Quote Link to comment 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.