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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:16:49+00:00 2026-05-16T10:16:49+00:00

I noticed that a lot of tutorial instructions often have this code: $sql=SELECT *

  • 0

I noticed that a lot of tutorial instructions often have this code:

$sql="SELECT * from table";
$num=mysql_num_rows();

if ($num > 0)
{
do something
}

Why do they have to use that condition “if ($num > 0)” when I write this code that I think is compact and readable:

$sql="SELECT * from table";
$itExists=mysql_num_rows();

if ($itExists)
{
do something
}

does mysql_num_rows ever return a negative integer? Doesn’t PHP always equate 0 to false? I’ve used this approach and noticed nothing different or unusual.

  • 1 1 Answer
  • 1 View
  • 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-16T10:16:50+00:00Added an answer on May 16, 2026 at 10:16 am

    Why would you assign the number of rows returned to a variable with a bool name like itExists? By doing this you are making information that could be used later less useful. It’s better to assign the number of rows (mysql_num_rows()) to a variable that says it holds a number of rows (numRows or in this case num).

    Having something like itExists assigned to 4, 5 or 6 isn’t good practice. It’s in this way that the first method is better.

    $pages = $numRows / $itemsPerPage;
    //works better than...
    $pages = $itExists / $itemsPerPage;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently noticed that a lot of JavaScript files on the Web start
Possible Duplicate: php false place in condition I have noticed that a lot of
I have a small project and I noticed that I have a lot of
I've just noticed that a lot of hpricot code is written in java... alt
I've noticed that a lot of projects have the following structure: Project-A bin lib
I have noticed that a lot of Pod has blank lines between the lines
I noticed that a lot of scripts have these type of comments: /** *
I have noticed that when writing specs you waste a lot of time on
I have noticed that a lot of websites display product information in special tabs
I noticed that a lot of sites send a random token with form posts

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.