Re: coding for 'no match found'

From: Date: Wed, 16 May 2001 00:33:38 +0000
Subject: Re: coding for 'no match found'
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-52963@lists.php.net to get a copy of this message
Or, try count() in the sql statement.. <? $sql = "SELECT count(email) from table WHERE email = '$email'"; $result = @mysql_query($sql); if (mysql_result($result, 0, "count(email)") == 0) { echo "No good."; } ?> I think that's faster than: <? $sql = "SELECT email FROM table WHERE email = '$email'"; $result = @mysql_query($sql); if (mysql_num_rows($result) == 0) { echo "No good."; } ?> Can't be sure where I read it, but still :) Ack! 1.20am. Bedtime. James. ""Johnson, Kirk"" <kjohnson@zootweb.com> wrote in message news:01A4B59FD1EBD311838100A0C98BE0D9AD5994@chef.zootweb.com... > See http://www.php.net/manual/en/function.mysql-num-rows.php > > Kirk > > > -----Original Message----- > > From: midget2000x [mailto:midget@elaris.com] > > Sent: Tuesday, May 15, 2001 3:00 PM > > To: php-general@lists.php.net > > Subject: [PHP] coding for 'no match found' > > > > > > This is a simple yet fundamental programming question I am > > hoping somebody will > > have the patience to explain... > > > > I have a mysql database with the "email" field as the key. > > Before inserting an > > new record to it I want to check if there is already a record > > with that e-mail. > > This I can do fine. But this script needs to also handle > > delete requests, > > which I can also do fine, but I need to code for the instance > > that there is a > > delete request for an e-mail record that does not exist. How > > can I figure out > > if after my 'while' loop is finished checking the database it > > has not found a > > match (so i can inform the requester as such)? > > > > Here's the code I have so far... > > > > $email_check_query = "SELECT email FROM > > $tablename WHERE email = '$email'"; > > $email_check_result = mysql_query($email_check_query); > > while($email_query_data = > > mysql_fetch_array($email_check_result)) { > > $db_email = $email_query_data["email"]; > > //if match, it's an update or delete > > if ($email==$db_email) { > > if ($op=="delete") { > > $action="del"; > > echo "delete > > request<br>"; > > } > > else { > > $action = "upd"; > > echo "update > > request<br>"; > > } > > } > > } //end while loop > > > > ----------- > > providing the finest in midget technology > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#52963) next »