PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 6th, 1999, 09:33 AM
pan
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Hi, how can I check if a user_id is already being used by another user and automatically tell the user that the id he/she requested is already in use (user_id is PRIMARY KEY and UNIQUE ID in a mysql table)
Thanks

------------------

Reply With Quote
  #2  
Old October 6th, 1999, 10:02 AM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
$result=mysql_query("select * from usertable where userid='$userid'");
$exists=mysql_num_rows($result);
if ($exists)
{
//username already used
}
else
{
//username not used
}

Reply With Quote
  #3  
Old October 10th, 1999, 09:38 AM
ExPulse
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Faster way

$result=mysql_query("select count(*) from usertable where userid='$userid'");
$number = mysql_fetch_row($result);
if ($number[0]>='1')
{
//username already used
}
else
{
//username not used
}

Reply With Quote
  #4  
Old October 12th, 1999, 07:24 AM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Yes and no.

Using count(*) would be faster when there is actual data returned i.e. userid is used AND the data returned is large. The fastest way would be to return a single field that contains an integer (the smaller the better) or a char(n) field where n is small (less than 5 characters). This reduces the overhead of returning large data and the overhead of mysql performing the count() function.

Using a boolean conditional is faster than a comparison.

The num_rows function is quicker than fetch_row because it returns an integer, not an array (doesn't matter that the array is one element and that element is an integer.)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > check for the uniqueness of an entry !?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap