[PHP] coding for 'no match found'

2001-05-15 Thread midget2000x

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 requestbr;
} 
else {
$action = upd;
echo update requestbr;
}
} 
} //end while loop

 ---
providing the finest in midget technology

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] coding for 'no match found'

2001-05-15 Thread Johnson, Kirk

See http://www.php.net/manual/en/function.mysql-num-rows.php

Kirk

 -Original Message-
 From: midget2000x [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, May 15, 2001 3:00 PM
 To: [EMAIL PROTECTED]
 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 
 requestbr;
   } 
   else {
   $action = upd;
   echo update 
 requestbr;
   }
   } 
   } //end while loop
 
  ---
 providing the finest in midget technology
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: 
 [EMAIL PROTECTED]
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] coding for 'no match found'

2001-05-15 Thread James, Yz

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 [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 See http://www.php.net/manual/en/function.mysql-num-rows.php

 Kirk

  -Original Message-
  From: midget2000x [mailto:[EMAIL PROTECTED]]
  Sent: Tuesday, May 15, 2001 3:00 PM
  To: [EMAIL PROTECTED]
  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
  requestbr;
  }
  else {
  $action = upd;
  echo update
  requestbr;
  }
  }
  } //end while loop
 
   ---
  providing the finest in midget technology
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail:
  [EMAIL PROTECTED]
 

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]