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! Link to comment https://forums.phpfreaks.com/topic/249844-could-someone-help-with-my-mailing-list-thank-you-in-advance/ 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 Link to comment https://forums.phpfreaks.com/topic/249844-could-someone-help-with-my-mailing-list-thank-you-in-advance/#findComment-1282413 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! Link to comment https://forums.phpfreaks.com/topic/249844-could-someone-help-with-my-mailing-list-thank-you-in-advance/#findComment-1282419 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. Link to comment https://forums.phpfreaks.com/topic/249844-could-someone-help-with-my-mailing-list-thank-you-in-advance/#findComment-1282421 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.