-
PHP Code:
<?php
//CONNECT TO MYSQL
$link = mysql_connect( $mysqladd, $mysqluser, $mysqlpass, true ) or die( 'Could not connect to database: ' . mysql_error() );
//CONNECT TO DATABASE
mysql_select_db( $databasename, $link ) or die( 'Could not connect to table: ' .
mysql_error() );
$query = "SELECT *, DATE_FORMAT(Time_of_Submission, '%Y/%m/%d') FROM jobadd WHERE Kategori='bygg' AND Time_of_Submission BETWEEN SYSDATE() - INTERVAL 1 DAY AND SYSDATE() AND sent = 0 ORDER BY ID DESC";
$query2 = "SELECT * FROM USERS WHERE Kategori='Bygg & Anläggning'";
$result = mysql_query( $query );
$result2 = mysql_query( $query2 );
//the email we are sending from
$fromemail = "no_reply@jobler.se";
//number of rows returned from our 2 queries
$link_count = mysql_num_rows( $result );
$users_count = mysql_num_rows( $result2 );
//check if there is at least 1 link to be sent and at least 1 user to get the email
if ( $link_count > 0 && $users_count > 0 )
{
//we should prepare the message in advance since all the users get the same email
while ( $mailmessage = mysql_fetch_assoc( $result ) )
{
$where = $mailmessage['where'];
$submitted = $mailmessage["Länk"];
// The subject
$subject = "Det har kommit in en ny Tjänstförfrågan på Jobler.se som passar er profil (klicka på länken nedan)";
// The message
$message .= $mailmessage['where'] . " " . $mailmessage['Länk'] . "\n";
//mark the link as sent
mysql_query("UPDATE jobadd SET sent = '1' WHERE id = '".$mailmessage['id']."'");
}
//now we will send the message to all the users
while ( $users = mysql_fetch_assoc( $result2 ) ){
$email = $users['email'];
if(mail($email, $subject, $message, "From: $fromemail"))
echo "<b><br>Sent to $email</b><br>Message: $message<hr><br>";
}
}
else
{
echo "We are sorry it looks like we have no links to send or no one to send them to!";
}
This assumes the newly added row is called sent and the you have a unique key in your jobadd table called id
-
That worked perfectly. Thank you so much for your help. I cant tell you how much it means to me, now i got a fully automatic Job ad system thank's to you'r help. So again i thank you.