Jump to content

Select random rows & then email


Horse

Recommended Posts

Hi All,

I'm a bit of a newbie and I'm a little stumped by this so if anyone can help it would be very much appreciated!

 

First here's a bit of table structure info...

 

Table: USERS

id  email

1    user@domain.com

 

 

Table: QUOTES

id  Link                      Quote

1    www.domain.com    blah blah...

 

 

What I need to do is create a script that, when executed, will send an email to each of the users in the USERS table with 10 random quotes/links from the QUOTES table. Can any of you experts point me in the right direction?

 

Thanks!!!

Link to comment
Share on other sites

Try this:

 

$query = "SELECT `email` FROM `users`";
$run = mysql_query($query);
while($arr = mysql_fetch_assoc($run)){
   extract($arr);
   $query2 = "SELECT `id`,`link`,`quote` FROM `quotes` ORDER BY RAND() LIMIT 0,10";
   $run2 = mysql_query($query2);
   $quotes = array();
   while($arr2 = mysql_fetch_assoc($run2)){
       extract($arr2);
       $quotes [] = array("link" => $link, "quote" => $quote);
   }
   // Email Script
   // To = $email;
   // Quotes = $quotes (this will be in the form of an array)
}

 

This should do the trick, just provide your email script where commented.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.