Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: php mysql

  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    Miami, FL
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php mysql

    what would be the code to check if an ID does NOT exists? i can do a long code, but i was wonderting is there is some kind of those funcstions that no one knows about from mysql

    thanks a lot
    MeGa MaX
    Be the Best, but don't Believe it.

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Do a query to see if it exists or not.
    PHP Code:
    $query mysql_query("SELECT id WHERE id='$idnumber'");
    if(
    mysql_num_rows($query) > 0)){
      echo 
    'ID exists';
    }else{
      echo 
    'ID doesnt exist';

    Or I guess I could've done
    PHP Code:
    $query mysql_query("SELECT id WHERE id='$idnumber'");
    if(
    $query){
      echo 
    'ID exists';
    }else{
      echo 
    'ID doesnt exist';

    Last edited by Nightfire; 01-03-2004 at 09:07 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually your second one wont work, as mysql_query returns true if the query is executed successfully, whether is returns any rows or not.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    lol I dunno why I came back 2 hours later and added the second bit in. Think the coffee is getting to me.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •