Actually, if I had spent more time thinking about it, I could have come up with 
an example less contrived than the alias, 'aaaa'.  Let's say the first entry in 
the table is the alias, 'williamson.'  Based on the current query, there can be 
no:
 
  'williams'
  'william'
  'willi'
  'will'
 
My previously stated assumptions still apply.  Of course, if the first entry is 
'will,' there could be a 'willi,' etc.
 
Regards,
Dave
 

        -----Original Message----- 
        From: Mitchell, David 
        Sent: Sun 10/2/2005 11:11 AM 
        To: php-db@lists.php.net 
        Cc: 
        Subject: RE: [PHP-DB] If syntax
        
        

        Please PMJI, but I'm new to PHP but have a little experience with 
databases, and I have a question:
        
        Is there a particular reason that LIKE is used in the query?  Let's say 
you had the contrived alias value in the table, 'aaaaa', and one wanted to add 
the alias, 'aaaa' (or fewer 'a's).  Wouldn't the query misreport that the 
alias, 'aaaa', already exists?
        
        I'm assuming that the number of characters in the alias can vary by 
some range (e.g., 3 to 10 characters), and that:
          "SELECT alias FROM tablename WHERE alias LIKE '$alias%' LIMIT 1";
        
        becomes:
          "SELECT alias FROM tablename WHERE alias LIKE 'aaaa%' LIMIT 1";
        
        at execution-time.
        
        Regards,
        Dave
        
                -----Original Message-----
                From: Jeffrey [mailto:[EMAIL PROTECTED]
                Sent: Sun 10/2/2005 3:32 AM
                To:
                Cc: PHP DB
                Subject: Re: [PHP-DB] If syntax
               
               
        
                See below...
               
                Ron Piggott wrote:
               
                >Take a look at my if ( ) syntax line below.  I am wondering if 
I have it
                >wrong in same way.  What I am trying to achieve is if the 
alias the user
                >enters is already found in the database I want the words 
"Alias already in
                >use" to be shown on the screen; otherwise "Unique alias" to be 
shown on the
                >screen.
                >
                >PRESENTLY alias already in use is what comes up all the time.
                >
                >Ron
                >
                >
                >mysql_connect(localhost,$username,$password);
                >@mysql_select_db($database) or die( "Unable to select 
database");
                >$query="SELECT * FROM tablename WHERE alias LIKE '$alias%'";
                >
                >if (mysql_query($query))
                >
                >{
                >
                >echo "Alias already in use";
                >
                >} else {
                >
                >echo "Unique alias";
                >
                >mysql_close();
                >
                >}
                >
                >
                >
                Whether or not there are any matches, you will always have a 
database
                query - hence mysql_query($query) will always produce something
               
                Instead you need to see if there are any  matches to your 
variable.
               
                Also, "SELECT * FROM [some_table] is tremendously inefficient 
when you
                only need to count results. You are basically calling up every 
result in
                your entire table just to see if a single column entry matches 
a variable.
               
                I would suggest something like..
               
                mysql_connect(localhost,$username,$password);
                @mysql_select_db($database) or die( "Unable to select 
database");
                $query="SELECT alias FROM tablename WHERE alias LIKE '$alias%' 
LIMIT 1";
               
                $result=(mysql_query($query))
               
                 if (mysql_num_rows($result)==1)
               
                {
               
                echo "Alias already in use";
               
                } else {
               
                echo "Unique alias";
               
                mysql_close();
               
                }
                Good luck,
               
                Jeffrey
               
                --
                PHP Database Mailing List (http://www.php.net/)
                To unsubscribe, visit: http://www.php.net/unsub.php
        
        NOTICE: This E-mail may contain confidential information. If you are not
        the addressee or the intended recipient please do not read this E-mail
        and please immediately delete this e-mail message and any attachments
        from your workstation or network mail system. If you are the addressee
        or the intended recipient and you save or print a copy of this E-mail,
        please place it in an appropriate file, depending on whether
        confidential information is contained in the message.
        
        --
        PHP Database Mailing List (http://www.php.net/)
        To unsubscribe, visit: http://www.php.net/unsub.php
 
NOTICE: This E-mail may contain confidential information. If you are not
the addressee or the intended recipient please do not read this E-mail
and please immediately delete this e-mail message and any attachments
from your workstation or network mail system. If you are the addressee
or the intended recipient and you save or print a copy of this E-mail,
please place it in an appropriate file, depending on whether
confidential information is contained in the message.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to