Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Search database and send email, depending on results
Old 08-29-2008, 01:18 PM Search database and send email, depending on results
Skilled Talker

Posts: 60
Trades: 0
I want to set a cron up that will check a database and send out emails depending on the results. I'm not 100% sure how to do this though. I know how to set the cron up, but wanted some help on the sending out the emails.
I want the database to be searched for numbers and if the same number has been entered by more than one person one email to be sent out, a different email to be sent out if only one person has selected a number. And another email to be sent out to the person with the lowest unique number. I've got:
PHP Code:
<?php
$con 
mysql_connect("hostname/server IP","username","password");
if (
DB::result("SELECT number FROM user WHERE number = number") != "")
        {
        
mail("SELECT email FROM user","You share your number");
        }

        else
        {
        
mail("SELECT email FROM user","Your number is unique");
        }
if (
DB::result("SELECT number From user WHERE number < ")
    {
    
mail("SELECT email FROM user","You have the lowest unquie number");
    }
mysql_close($con);
?>
but am not sure if I've got the syntax right or if it will work. I'd be grateful for any help please.
Thanks
thehappyappy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-31-2008, 05:52 AM Re: Search database and send email, depending on results
Novice Talker

Posts: 9
Trades: 0
Let's say you have a datababase containing id,user,email, number .
This is how i will do it:
PHP Code:
 
$con 
mysql_connect("hostname","username","password"); 
$first TRUE;
 
$result mysql_query("SELECT * FROM database");
while (
$row mysql_fetch_row($result))
 {
   
$email $row['2']; 
   
$number $row['3']; 
   
$resultnr mysql_query("SELECT * FROM database WHERE number= " .$number);
  
$count mysql_num_rows($resultnr);
 
if (
$count == 1
     {
       
mail($email,"Your number is unique"); 
 
      if (
$first)
       {
         
$lowest $number;
         
$first FALSE;
       }
     else
      {
         if (
$number $lowest)
           {
             
$lowest $number;
           } 
      }
   }
    else
   {
      
mail($email,"You share your number"); 
   }
 
}
 
$result mysql_query("SELECT * FROM database WHERE number =".$lowest);
$row mysql_fetch_row($result);
$email $row['2']; 
mail($email,"You have the lowest unquie number"); 
I didn't have much time to test it, but it will probably work.
__________________

Please login or register to view this content. Registration is FREE

Last edited by propress; 08-31-2008 at 05:54 AM..
propress is offline
Reply With Quote
View Public Profile
 
Old 09-01-2008, 05:00 AM Re: Search database and send email, depending on results
Skilled Talker

Posts: 60
Trades: 0
Brilliant, thank you. I'll build the form and test it. I'll let you know how I get on
thehappyappy is offline
Reply With Quote
View Public Profile
 
Old 09-02-2008, 12:26 PM Re: Search database and send email, depending on results
Skilled Talker

Posts: 60
Trades: 0
Okay, it does work, but not quite properly. It sends all of the emails to the same email address (the one specified in the php.ini file) rather than the email address of the person with that number.
thehappyappy is offline
Reply With Quote
View Public Profile
 
Old 09-02-2008, 02:06 PM Re: Search database and send email, depending on results
Novice Talker

Posts: 9
Trades: 0
I never used the mail function but i know that it should look like this:
PHP Code:
mail($recipient$subject$mail_body$header); 
Maybe that's the problem.
__________________

Please login or register to view this content. Registration is FREE
propress is offline
Reply With Quote
View Public Profile
 
Old 09-03-2008, 05:04 AM Re: Search database and send email, depending on results
Skilled Talker

Posts: 60
Trades: 0
okay, thanks I'll try that
thehappyappy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Search database and send email, depending on results
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29060 seconds with 12 queries