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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:57:48+00:00 2026-05-25T14:57:48+00:00

I have the following MySQL query, and PHP code to format the Count result

  • 0

I have the following MySQL query, and PHP code to format the Count result in a single array:

$equalDimensions_query = 
"SELECT 'allEqual' AS COL1,COUNT(*) AS imgCount FROM (
    SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images
    UNION ALL 
    SELECT imgHeight, imgWidth, primaryId FROM secondary_images
) AS union_table
WHERE primaryId = $imgId AND imgWidth = $maxImageWidth AND imgHeight = $maxImageHeight
UNION ALL
SELECT 'widthEqual' AS COL1,COUNT(*) AS imgCount FROM (
    SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images
    UNION ALL 
    SELECT imgHeight, imgWidth, primaryId FROM secondary_images
) AS union_table
WHERE primaryId = $imgId AND imgWidth = $maxImageWidth AND imgHeight != $maxImageHeight
UNION ALL
SELECT 'heightEqual' AS COL1,COUNT(*) AS imgCount FROM (
    SELECT imgHeight, imgWidth, imgId AS primaryId FROM primary_images  
    UNION ALL 
    SELECT imgHeight, imgWidth, primaryId FROM secondary_images
) AS union_table
WHERE primaryId = $imgId AND imgWidth != $maxImageWidth AND imgHeight = $maxImageHeight";

$equalDimensions_data = mysql_query($equalDimensions_query) or die('MySql Error' . mysql_error());

while ($row = mysql_fetch_assoc($equalDimensions_data)) { 
    $cnt[$row['COL1']] = $row['imgCount']; 
}

var_dump($cnt);

(Notice I included var_dump($cnt) as the last line)

The var_dump returned the following array:

array
(
  'allEqual' => string '2' (length=1)
  'widthEqual' => string '0' (length=1)
  'heightEqual' => string '0' (length=1)
)

I’m curious why the count is being returned as a string, and not as an integer?

Should it be returned as an integer? Or is it the norm when dealing with count queries, for the result to be returned as a string?

Thanks.

  • 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-25T14:57:49+00:00Added an answer on May 25, 2026 at 2:57 pm

    from http://www.php.net/manual/en/function.mysql-fetch-assoc.php:

    Returns an associative array of strings that corresponds to the
    fetched row, or FALSE if there are no more rows.

    (emphasis mine) It’s probably just easier for the MySQL driver to give you everything as a string, and assume you will know what to do with it. Just use intval() to get the integer value.

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

Sidebar

Related Questions

I have the following PHP/MySQL code: function executeMultirowQuery($query) { $result = mysql_query($query); $table =
I have the following MySQL query that I execute from a .php page SELECT
I have PHP code snippet the following: if (!($result = mysql_query($query, $link))) { die(Invalid
I have the following mysql query which I am running with php like so.
I have an application that executes the following MySQL query: SELECT 402 AS user_id,
I have the following code: (query added) $weight_table = mysql_query (SELECT * FROM .$prefix.weight
I have the following piece of code, executing a pretty simple MySQL query: $netnestquery
I have the following code: <?php include('settings.php'); //Here I have my connection string $result
I have the following php code: $seasons = array(Autumn, Winter, Spring, Summer); Now I
I have the following sample query (MySQL): SELECT * FROM `action` WHERE `customer_id` IN

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.