Jump to content

If array total is equal to echo message if greater display different message


Texan78
Go to solution Solved by Texan78,

Recommended Posts

Hello, I am having some issues with some else if statements I am currently working on where if a certain value is equal to a certain number display a certain message else if greater then display a different message. I have tried a number of different combinations without success. 

 

What I am trying to accomplish is if the total number of "true" statements from the array is 1 display $notify1Online message and if it is 2 or greater the display the $notifyOnline message else display the $notifyOffline message. I have gone through the PHP manual and done a number of research and played with some different combinations but cannot seem to get this to work. Could someone offer some assistance as to what I am doing wrong. 

$resultArr = array();//to store results

//lets execute the query
$executingFetchQuery = $mysqli->query("SELECT `StreamStatus` FROM streamdb WHERE 1");
if($executingFetchQuery)
{
   while($arr = $executingFetchQuery->fetch_assoc())
   {
        $resultArr[] = $arr['StreamStatus'];//storing values into an array
   }
}

$counts = array_count_values($resultArr);//lets count the results
$online = $counts['true'];
$total = (in_array("true", $resultArr));

// Lets assemble the banners to display
$notifyOffline = '<div class="alert alert-danger" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There are currently no active chasers online streaming at this time.</div>';

$notify1Online = '<div class="alert alert-success" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There is currently 1 chaser streaming LIVE... </div>';

$notifyOnline = '<div class="alert alert-success" role="alert" data-toggle="tooltip" data-placement="top" title=" "> There are currently '.$online.' chasers streaming LIVE... </div>';


//lets display the banners
if ( $total = "1" ) {
    echo $notify1Online;
} elseif ( $total < "2" ) {
    echo $notifyOnline;
} else {
    echo $notifyOffline;
}

-Thanks!

Link to comment
Share on other sites

  • Solution

Got this resolved. Helps if I was using the right variable to get the correct value. Was using $total when I should have been using $online which is why the == wasn't working when I first tried it as it was suppose to be. 

//lets display the banners
if ( $online == "1" ) {
    echo $notify1Online;
} elseif ( $online >= "2" ) {
    echo $notifyOnline;
} else {
    echo $notifyOffline;
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.