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 8470813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:37:28+00:00 2026-06-10T16:37:28+00:00

I have this PHP code of: $count = select count(fruit) as total, sum(fruit like

  • 0

I have this PHP code of:

$count = "select 
              count(fruit) as total,
              sum(fruit like '%apple%') as apple,
              sum(fruit like '%orange%') as orange
          FROM my_wonderful_table_of_fruits";

$count = mysql_query($count);
$count = mysql_fetch_row($count);

I’m trying to store these in a variable and can’t seem to catch them :/

My code is:

while ($row = mysql_fetch_array($count)) {
    $count_total = $row['total'];
    $count_apple = $row['apple'];
    $count_orange = $row['orange'];
}

And I was expecting to be able to echo them like so:

echo "$count_total[0] is the total of $count_apple apples and $count_orange oranges

When I run this query in MySQL Admin, I get a nice row that looks like:

total    apple    orange
  5        3         2

Anyone know how what I’m doing wrong? (besides the fact that I’m using the ‘evil’ version of mysql_fetch_row)

Much appreciated!

  • 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-06-10T16:37:30+00:00Added an answer on June 10, 2026 at 4:37 pm

    You need to reanalyse what you’re doing. Your SQL will only return one row with some aggregate results, but it seems you expect to be able to iterate over several rows of results (due to your while()).

    What your sql does and how you’re trying to use it are two different things.

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

Sidebar

Related Questions

I have this PHP code: $query = SELECT name, COUNT(message) FROM guestbook_message WHERE name='.$req_user_info['username'].'
I have code like this: <?php if(isset($global_info_results)): ?> <?php echo count($global_info_results) ?> <span>Mali Oglasi:
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
so I have this query: SELECT COUNT( * ) AS cnt FROM table WHERE
I'm using this php to fetch data from my mysql database: $wpdb->get_var(select count(*) from
So, I have this PHP code: $tabid = getTabid($module); if($tabid==9) $tabid=9,16; $sql = select
I have this code: <?php $fql = SELECT url, normalized_url, share_count, like_count, comment_count, ;
This is my php code: <?php require('connection.php'); $query=select title,content from blogs; echo '<html><head>'; echo
I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
I have this PHP code in a loop for every post on the admin

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.