Horse Posted January 24, 2008 Share Posted January 24, 2008 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/ Share on other sites More sharing options...
p2grace Posted January 24, 2008 Share Posted January 24, 2008 To grab ten random quotes use the following: $query = "SELECT `id`,`link`,`quote` FROM `quotes` ORDER BY RAND() LIMIT 0,10"; $run = mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/#findComment-448097 Share on other sites More sharing options...
Stooney Posted January 24, 2008 Share Posted January 24, 2008 edit: p2grace had a better solution. Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/#findComment-448103 Share on other sites More sharing options...
Horse Posted January 24, 2008 Author Share Posted January 24, 2008 Thanks for that. What about getting it to mail it to each of the users. I know how to write a mailer script but just not sure how I get it to send to each of the users? thanx Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/#findComment-448113 Share on other sites More sharing options...
p2grace Posted January 24, 2008 Share Posted January 24, 2008 Do you want it to send a separate email to each one, or include all of the users on the same email? Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/#findComment-448117 Share on other sites More sharing options...
Horse Posted January 24, 2008 Author Share Posted January 24, 2008 Send 10 different ones to each user so it will be separate emails. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/#findComment-448177 Share on other sites More sharing options...
p2grace Posted January 24, 2008 Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87602-select-random-rows-then-email/#findComment-448233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.