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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:45:55+00:00 2026-05-13T19:45:55+00:00

I have a classifieds website, and it is using MySQL as a database. My

  • 0

I have a classifieds website, and it is using MySQL as a database.

My goal is to show the number of private, company and total ads in the db with the search-term entered in a text-input inside the form!

The Problem:
There are two types of ads: Private, and Company.
The user may specify which to display, or both, so thats three options.

On the website, after displaying the search results, I want to show the user THREE tabs: All ads, Private ads, Company ads.

I have a field in every record in MySQL which contains the value of either Private or Company.

I know of a way to display the number of private ads, company ads and TOTAL ads but it requires multiple queries.

For example, if the user CHECKS the PRIVATE ONLY check-box then only private ads are searched, but I won’t know how many company ads there are until I make a new query, where I search also for company ads. Then add them, and I have also the total nr of ads.

Just wonder if you know of a good way, to maybe get rid of the extra query?

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-13T19:45:55+00:00Added an answer on May 13, 2026 at 7:45 pm

    You could use a ROLLUP:

    SELECT
        IFNULL( field , 'All ads' ) AS 'Type',
        COUNT( * )
    FROM
        `table`
    GROUP BY
        field
    WITH ROLLUP
    

    So with four Company and one Private ad you would see:

    Type       COUNT( * )
    Company    4
    Private    1
    All ads    5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a classifieds website, and users can search ads. The results are displayed
I have a php classifieds website (mostly) and I am currently using MYSQL as
I have a classifieds website where users may search ads. I wonder if I
I have a classifieds website. I am using SOLR for indexing and storing data.
I have a classifieds website, and I have currently around 100thousand ads in a
I have a classifieds website. The users first have to specify their 'area of
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have a n-tire web application and search often times out after 30 secs. How

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.