mrlol12 Posted October 26, 2011 Share Posted October 26, 2011 Hi guys, I was just wondering if anyone could help me. I've got a My_SQL database containing articles, a summary for the article and a date. I have a basic CMS system set-up, but I want to create a script that when users sign up to a mail list it forwards the summary and dates of the articles database. If that makes sense? But I only want it to forward the most recent 5 rows. I'm pretty new to PHP and I've been mostly following tutorials thus far, but this is quite specific. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Nodral Posted October 26, 2011 Share Posted October 26, 2011 Hi It's fairly straight-forward. Run a MySQL SELECT statement to pull the data from the table and add ORDER BY `date` DESC LIMIT 5. This will effectively give you the 5 most recent database entries for you to attach / include in your emails Quote Link to comment Share on other sites More sharing options...
mrlol12 Posted October 26, 2011 Author Share Posted October 26, 2011 Hi there, Thanks for that. So in an e-mail I can ad the variable say... $mailContent = "SELECT * FROM articles WHERE 'date' . 'title' . 'summary' ORDER BY 'id' DESC LIMIT 5" Into the e-mail itself? And that would pull through the top 5? I only wanted certain column to pull through also, so would the way I have put it above work? Also, how would I actually go about making an e-mail automatically send out per month? Cheers! Quote Link to comment Share on other sites More sharing options...
Nodral Posted October 26, 2011 Share Posted October 26, 2011 You'd need a lot more than that. <?php // create sql statement to get information from DB $sql="SELECT columnName FROM articles ORDER BY date DESC LIMIT 5"; //run the query against the DB $sql=mysql_query; //set variable to count the items $a=0; //create array containing all data pulled from DB anc cycle through it to do what you want while($row=mysql_fetch_array($sql){ //create array of 5 variables containing individual items $mailContent['$a']=$row['columnName']; //increment your counter $a++; } Regarding mailing it out, I personally use Rmail. Do a google for it, it'll save you loads of time. Then all you do is create your mail it include items (You can get them out of the array easily using a foreach loop) Regarding sending periodic emails, you need to look into cron jobs and have a reference in your DB table as to when the last one was sent out. Quote Link to comment 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.