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    [email protected]

 

 

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
https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.