Hello DaniWeb,
I want to develop PHP application, when there is Entry in specific table of database, it should send that information to subcribers on their emails, i am new to PHP. Suggest me solution to this problem.

Thanks:

Recommended Answers

All 6 Replies

Member Avatar for diafol

Suggest me solution to this problem.

You want us to do a Google search for you or do you want us to write code for you? I also double as a doormat.

I think this is something you have to set up on your server. You can have some sort of program (maybe in C#, python, perl) that will sit and wait database updates, and then handle sending the emails.

I'm fairly sure you can also use your OS command line to run programs in the background (such as a PHP script) which will run in a similar way. Your PHP will have a function that checks for any changes (using something like a primary key -> is the largest id in the table different to the last time?), and then have another function to deal with the mail if a change is detected:

<?php
/* Script that notices changes in databases, quickly dreamed up by @mattster */
class MailSystem
{
    public $current_id;

    private function __construct()
    {
        $this->current_id = $this->get_id();
    }
    private function get_id()
    {
        $sql = "SELECT `id` FROM `table` ORDER BY `id` DESC LIMIT 1";
        // Connect and run the query here
        return $result_from_your_qry; // i.e. value should be something like "10"
    }
    private function check()
    {
        $key = true;
        while($key){
            if($this->get_id() > $this->current_id())
            {
                $key = false;

                // call the mail handling script
            }
        }
    }
}
$mail = new MailSystem();
$mail->check();
?>

Then have a table with an auto_increment "id" column and use that as a reference point. This is untested code, so it is ONLY to be used to get a rough idea.

But the main point to your question is running a script in the background, which may be difficult on most hosting packages. So unless you're writing it for something specific (which to be honest you probably are), most webmasters would struggle to get any script of this nature working on their websites - just something to bare in mind.

Sorry @diafol, didn't read your comment before posting that.

Member Avatar for diafol

No prob - your time and effort, not mine. I just have an issue with "gimme" posts. But we should try to avoid feeding them if possible. I should try to be less sarcastic too. Trying - really I am, it's so hard though.... :)

Without sarcasm th world would be a very very boring place aha ;)

we should try to avoid feeding them if possible.

Will do, but hopefully still useful to Googlers if they find this one day I guess

Member Avatar for diafol

Indeed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.