Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Jun 2003
    Posts
    10
    Member #
    1767
    Hey, I have a simple question that I couldn't find any answers to on my own...

    I am doing a mysql_query to detect whether or not an archived ID is used more than once, and to do so, I compare an $id variable with all of the ID entries in my database. This works fine for detecting duplicated ID's, but I can't figure out what PHP returns of there is no duplication found. I tried "", NULL, empty, isset, and all kinds of other weird characters, but none of them worked. If I echo it, i get "Resource ID #3".

    What does it return, or how can I write a statement to detect these unsuccessful searches?

    Thanks,

    -Doodler

  2.  

  3. #2
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Not sure about the code you are using, if you could post it here, that would help.

    Here is what I would use:

    PHP Code:
    // $id contains the ID

    $sql "SELECT COUNT(id) FROM table WHERE id=$id";
    $results mysql_query($sql);
    list(
    $counted_ids) = mysql_fetch_row($results);

    // $counted_ids contain an integer which holds the
    // count of all the rows with same ID you had in $id,
    // use it for comparisons. 
    HTH
    There and Back Again :Ogre:

  4. #3
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    read up on the functions... mysql_query returns a value IF THE SQL SYNTAX IS CORRECT. Meaning, if there are 0 records found, it will still return a value. I forget exactly what it returns, but I believe it's something like the resource ID#... Something like the above would work correctly, good luck
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    I think nsr's example would work perfectly. You get 0 if the id doesn't exist... 1 if it exists only once, or > 1 if there are duplicates.

  6. #5
    Junior Member
    Join Date
    Jun 2003
    Posts
    10
    Member #
    1767
    I love you guys.

    *cries*

    Thanks so much. Where can I find more detailed info about mySQL? I learned from www.sqlcourse.com and www.sqlcourse2.com, but they didn't ever teach COUNT and stuff like that (unless I overlooked it).

    -Doodler

  7. #6
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    www.mysql.com The whole manual's on there

    I'm not sure if that'll help you... I learn more by looking up stuff in manuals than I do by books Experience is the best tool That and helping others... stay around here for a while, or go to some popular channel in irc #php on efnet is a good choice (as most php problems arise from mysql).. etc. COUNT is a useful tool
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:41 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com