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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:14:41+00:00 2026-05-14T04:14:41+00:00

How to list records for a query and to display no records when no

  • 0

How to list records for a query and to display “no records” when no rows returned using a single query?

Currently I am using a COUNT(*) query or using mysql_num_rows() function; then another query in different result set to list data. Can you tell me if it is possible to accomplish the same with a single query?

  • 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-14T04:14:42+00:00Added an answer on May 14, 2026 at 4:14 am

    Important: I assume that the OP uses PHP as (s)he mentions mysql_num_rows. And I hope (s)he will tell me if I am wrong.


    It is your job in PHP to check whether the result is an empty set or not. I don’t understand why you have to do another query. Maybe you have to clarify your question.

    Here a more complete example:

    $link = mysql_connect("localhost", "mysql_user", "mysql_password");
    mysql_select_db("database", $link);
    
    $result = mysql_query("SELECT * FROM table1", $link);
    
    // If if result set contains rows
    if(0 == mysql_num_rows($result)) {
        echo 'no records';
    }
    else { // Loop over the result set
        while(row = mysql_fetch_array($result)) {
           // do whatever you want with the data here
        }
    }
    

    Reference: mysql_num_rows, mysql_fetch_array


    Even if you don’t use PHP, the approach is the same in other languages and there should be similar functions available.

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

Sidebar

Related Questions

I would like to display a list of records from my database, then for
With this javascript I'm printing list of records: <script type=text/javascript> $(document).ready(function(){ function hide(){ $('#friend_list').fadeIn(100);
I am displaying a list of customer records from SQL Server using L2S where
I'm using LINQtoSQL and I want to return a list of matching records for
I have system in which I need to display the list of records such
I have this code I'm using to generate a list of records categorized into
In a continuous subform, I display records based on a DISTINCT query. Because it's
I would like to create a list of records. I can add one record
I am attempting to populate a list of records within the last X seconds
I have the script shown below that displays a list of records from a

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.