Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6596567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:05:34+00:00 2026-05-25T18:05:34+00:00

I am trying to get a 0 result from this foreach loop but it

  • 0

I am trying to get a 0 result from this foreach loop but it just stays blank. However it does execute the else if part.

I just want to display entries from a database. If there is no entry I just want a plain 0.

$entries = array();


$sql = "SELECT   `id`   FROM   `events` where creator_id='$id'  ORDER BY  `id` DESC         
LIMIT 1";


 $query = mysql_query($sql);
 while(($row = mysql_fetch_assoc($query)) !== false)
 {
 $entries[] = $row['id'];
  }


$value1 = "0";
foreach($entries as $entry) 
{  
  if ($entry == false) 
   {
    echo "0";
   }      
  else 
 if($entry > $value1) 
  {
   echo "$entry";
   }
} 

what might the problem be here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:05:35+00:00Added an answer on May 25, 2026 at 6:05 pm

    Try this:

    if (count($entries) == 0)
        echo "0";
    else foreach($entries as $entry)
    {
        if($entry > $value1)
        {
            echo "$entry";
        }
    }
    

    Note that this may still display nothing if everything in $entry is <= $value1. You may want to move that logic to your SQL statement, depending on exactly what you are trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I am trying to use LINQ on a result i get from Client Object
I'm trying to get the result of a COUNT as a column in my
Hopefully I can explain this to where it make sense, but I'm trying to
This question is as a result of trying Jon Skeet's answer to this question
<c:set var=nameLookup value=${names} /> <c:forEach var=result items=${results}> <tr> <td>${result.uglyDisplayName}</td> <td>${result.phonenum}</td> </tr> </c:forEach> This is
I am trying to make this function that extracts text from html for multiple
hey guys, i manage to get this script working to pull data from my
I'm trying to get some data from my database, and then pass it into
I am trying to get the following output format from a CI query and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.