• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

[TFS 1.2] Cast website

president vankk

Web Developer & AuraOT Owner
Joined
Jul 10, 2009
Messages
5,719
Solutions
9
Reaction score
339
Hi everyone, I'm using djarek's cast system and I'm having a problem to how many casts are online and how many spectadors does it have.

I'm using the code below and having this problem:

OyqVii.png


Code:
$cast = $SQL->query('SELECT COUNT(*) FROM `live_casts` WHERE `player_id`>0;')->fetch();
     $spectators = $SQL->query('SELECT SUM(`spectators`) FROM `live_casts`;')->fetch();

<strong><?php echo ' '.$cast[0].''; ?></strong> cast online with <strong><?php echo ' '.$spectators[0].''; ?></strong> spectators.

Thanks.
 
SUM returns NULL when there are no rows in a table. However you can use IFNULL or COALESCE around SUM to return 0 instead of NULL.

Code:
IFNULL(SUM(`spectators`), 0) -- Returns the first expression if it's a non-NULL value, otherwise it will return the second expression.
Code:
COALESCE(SUM(`spectators`), ...) -- Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
 
Back
Top