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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:08:13+00:00 2026-05-26T06:08:13+00:00

i’m very new to using mysql with php, and here’s what i found online

  • 0

i’m very new to using mysql with php, and here’s what i found online to retrieve my results:

$con = mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Cannot connect to the database");
$query = "SELECT ... FROM ... WHERE ID=5";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num > 0 ) {
    // do stuff
} else {
    // inform user
}
mysql_close($con);

ID is my table’s autogenerated non-null primary key. right now, i have 20 records in my table. if i enter an ID value corresponding to any of these existing records, everything goes well and works as intended.

however, if i enter an ID value of, say, 54 or anything that doesn’t correspond to any of my existing 20 records (meaning no row with such an ID exists), i expect $num <= 0 and my conditional statement will go to the else block. but i found out that wasn’t the case – it still goes to the TRUE branch and proceeds to // do stuff block, so i ran the query on phpmyadmin and found out that i’m getting exactly 1 row with NULL in all of the fields. that’s why $num was returning 1 which is >0.

questions:

  1. how do i properly go about checking for nonexistent rows? so that the rest of my script will only run if i actually get a row that contains data.
  2. i found mysql_store_result and mysql_free_result while researching this online but there’s not enough info to make them work properly. like where in my code do i place them, how come i can do what i need to do right now in php even without them, etc?
  3. any “best practice” stuff i’m missing here when dealing with mysql databases in php?
  4. when i have to call several sql statements, what i do is cycle through the $query–$result–$num process before i mysql_close my connection. is that “best practice”?

thank so much, guys, you’re all amazing.

UPDATE: Including whole query

SELECT Dyna, 
       Floater, 
       Can.Label as CanLabel, 
       GROUP_CONCAT(DISTINCT Vanity.Name SEPARATOR ', ') as VanityName, 
       GROUP_CONCAT(DISTINCT Univ SEPARATOR ', ') as Univ, 
       ShopDate, 
       ManuDate, 
       FlipTran, 
       Remarks, 
       Bib, 
       Abbrev, 
       ShopChar, 
       Comment, 
       Value, 
       ERUSD 
       FROM 
       (Vanity INNER JOIN ((Vanity INNER JOIN Shoppy ON Vanity.VanityID = Shoppy.VanityID) INNER JOIN ShoppyVanity ON Shoppy.ID = ShoppyVanity.ID) ON Vanity.MethodID = ShoppyVanity.MethodID) INNER JOIN UAC ON (Shoppy.VanityID = UAC.VanityID) AND (Vanity.VanityID = UAC.VanityID) 
        WHERE (((Shoppy.ID)=5))
  • 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-26T06:08:14+00:00Added an answer on May 26, 2026 at 6:08 am

    If you use group aggregate functions such as GROUP_CONCAT MySQL will create a group out of your whole result set. If there are no results, it will run them on NULL values instead, resulting in an empty row. Try adding this to the very end of your query to get rid of rows that don’t have valid data in them:

    HAVING VanityName IS NOT NULL

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker

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.