Jump to content
MakeWebGames

Checking if someone is on the hitlist


gurpreet

Recommended Posts

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.   Paste as plain text instead

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