I am having a problem with the logic of this code. It seems to be working fine with the exception of a small detail (i think) In my database, i have 5 fields: Artist_Name, City, Genre_Select, Contact, and Updates.
What i need to do is send the Artist_Name of new records (created in the past 7 days) to the Contacts of already existing members. The criteria is that the Contacts have the same City OR Genre_Select fileds AND have answered 'Yes' to Updates.
In my database, I have 3 Contact emails of existing members, lets call them X, Y, and Z. Also in my database, I have 4 Artist_Names of newly created entries, lets call them A, B, C, and D. Now here is the problem - When i check the emails of the contacts, i am getting the correct data, but it is data that has accumulated for all of the contacts. Here is my example:
Email for Contact X:
Artist Name(s): B, C, D (this is actually the correct answer
because this is the FIRST contact)
Email for Contact Y:
Artist Names(s): B, C, D, A, D (should be just the last 2 -
A,D. B, C, D is from Contact X.)
Email for Contact Z:
Artist Name(s): B, C, D, A, D, B, C (should be just the last 2
again - B,C. B,C,D is from
Contact X and A,D is from
Contact Y
What is happening is that the Arist Names are being diplayed correctly with the corresponding contact, however, i am getting accumulated data. What i would like is just the immediate data displayed for the corresponding contacts -
Contact X: B,C,D
Contact Y: A,D
Contact Z: B,C.
I hope this makes sense. Here is my code:
$updatefolks = mysql_query("SELECT City, Genre_Select, Contact FROM Musicians_Network WHERE Updates = 'Yes' ", $db);
while ($updaterow = mysql_fetch_array($updatefolks))
{
$to = $updaterow["Contact"];
$genre = $updaterow["Genre_Select"];
$city = $updaterow["City"];
$newentries_query = "SELECT Artist_Name FROM Musicians_Network WHERE Date_Created > DATE_SUB( CURDATE(), INTERVAL 7 DAY ) AND ( Genre_Select = '".$genre."' OR City = '".$city."' ) Order by Artist_Name";
$newentries = mysql_query($newentries_query, $db);
while ($newentry = mysql_fetch_array($newentries))
{
$body = $body.", ".$newentry["Artist_Name"];
}
$update_subject = "A new artist in your city or genre has been added";
$update_extra = "From: Boggle_Productions<>\r\nReply-To: ()\r\n";
$update_message = "These Artists from your city or genre have been added in the Musicians Network:
$body";
mail($to, $update_subject, $update_message, $update_extra);
}