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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:47:29+00:00 2026-06-05T20:47:29+00:00

Here is a simple scenario I am contemplating. I have a query that is

  • 0

Here is a simple scenario I am contemplating. I have a query that is executed on a MySQL database from PHP. I would like to check if any data was returned from the query. However, in order to perform that check, it pulls out one of the rows of returned data.

Look at this example, and its comments:

$booksGrabber = ("SELECT * FROM table");

if (!$booksGrabber) {
  //Query failed, perhaps a syntax error
  exit;
}

if (!mysql_result($booksGrabber, 0)) {
  //No data was returned :(
  exit;
}

while ($book = mysql_fetch_assoc($booksGrabber)) {
  //mysql_result() stole the first row of returned data
  //So if I was expecting the loop to display 4 results,
  //I only get 3...
}

How can I check if data was returned from the database without running two queries (one to check, the other to display all of the data) or having one of the rows stolen?

  • 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-05T20:47:32+00:00Added an answer on June 5, 2026 at 8:47 pm

    Use mysql_num_rows. It was as simple as it looked.

    EDIT: If you want more complicated, add mysql_data_seek($booksGrabber,0).

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

Sidebar

Related Questions

I'm hoping that i'm simply overlooking something simple. But here the scenario. I have
Here is a simple scenario: I have a blog post with comments attach to
I have a quite simple scenario that I cannot get to work correctly. I
Here is a simple scenario: assuming I have two Core Data entities: A and
Ok, here's my simple scenario. I've got collection of strings that I'm binding to
Here is the simple scenario that I want to apply; There is a .NET
I have (what I feel to be) a very simple scenario that I can't
my question is very simple. here is my scenario: i have 1 result dataset[named=resultDS
Here's my simple ideal case scenario for when I'd like delayed job to run:
Here is the scenario: a simple website which queries a memcached cache. That same

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.