Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2004, 07:05 PM   PM User | #1
MeGa
New Coder

 
Join Date: Dec 2003
Location: Miami, FL
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
MeGa is an unknown quantity at this point
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.
MeGa is offline   Reply With Quote
Old 01-03-2004, 07:43 PM   PM User | #2
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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';

__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks

Last edited by Nightfire; 01-03-2004 at 09:07 PM..
Nightfire is offline   Reply With Quote
Old 01-03-2004, 09:18 PM   PM User | #3
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
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)
ReadMe.txt is offline   Reply With Quote
Old 01-03-2004, 09:21 PM   PM User | #4
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
lol I dunno why I came back 2 hours later and added the second bit in. Think the coffee is getting to me.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:06 AM.


Advertisement
Log in to turn off these ads.