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

  • SEARCH
  • Home
  • 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 7577019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:04:46+00:00 2026-05-30T17:04:46+00:00

Can I assign 0 value on an array that returned no results from a

  • 0

Can I assign “0” value on an array that returned no results from a MySQL Query?

If so, can you show me how?

my code goes something like this:

    $grapes_query = mysql_query("SELECT fruitDate, fruitName, COUNT(*) FROM tbl_fruits WHERE fruitName='Grapes' GROUP BY 

    fruitDate");
    while ($grapes = mysql_fetch_assoc($grapes_query)){
    $grapes_array[]=$grapes['COUNT(*)'];

}

What if in a day, no grapes were found, can I assign “0” to its array value?

Let’s say 1/1/2012 = 3 grapes were counted, 1/2/2012 = no grapes were counted, 1/3/2012 = 5 grapes were counted..so the array should be like this.

$grapes_array[0]=3;
$grapes_array[1]= <-- i want to assign a string or number here when a MySQL query is empty.
$grapes_array[2]=3;

i’m getting errors if no value was found.

UPDATE:

enter image description here

fruit names should be grapes…:(

UPDATE 2:

HERE is my sample database being used.

enter image description here

Here is the result I’m getting on your updated query

enter image description 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-30T17:04:48+00:00Added an answer on May 30, 2026 at 5:04 pm

    The updated query will provide dates where there are fruit counts, but no Grapes counted on that day

    $grapes_query = mysql_query("SELECT f.fruitDate, IF(ISNULL(f1.count), 0, f1.count) as count FROM tbl_fruits f
        LEFT JOIN (SELECT fruitName, fruitDate, COUNT(*) as count from tbl_fruits d WHERE d.fruitName='Grapes' GROUP BY d.fruitDate) as f1 ON (f.fruitDate = f1.fruitDate) 
        GROUP BY f.fruitDate");
    while ($grapes = mysql_fetch_assoc($grapes_query)){
       // use the fruitDate as a key for the array
       $grapes_array[$grapes['fruitDate']]= $grapes['count'];
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to return a value from a VB.NET function one can assign a
Can I assign the values to datagridview cells at a time like datagridview1[0,0].value =
Can I assign each value in an array to separate variables in one line
I'm making a short database application where people can assign variables to something. like
I have been trying to assign value to an object array that is defined
I'm trying to assign a value with code like the following: findItemByCategoryRequest r =
can we assign null value to struct type of variable? struct MyStruct { }
My question is if we can assign/bind some value to a certain item and
How can we re assign the value of a StringBuffer or StringBuilder Variable? StringBuffer
I'd like to know how I can assign in XAML a dependency property of

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.