Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should at least get you started. Keep in mind I don't know the structure of your DB so you may have to change some things. Also this is <em>by FAR</em> not the most efficient way to do it, but it is easy to follow, you can do this in a single MySQL query instead of looping over each user id (which I show an <em>untested</em> example of see ---faster way---), but again I don't know about your DB structure so you'll have to play with it, plus this way does exactly what you do now, one at a time so hopefully it's easier to follow and you can mod it to be more efficient later. Backup your db before playing with this.</p> <p>PHP script to do what you want:</p> <pre><code>&lt;?php //put your search terms in this array $search_terms = array('yahoo', 'google', 'bing'); //conenct to your DB $db_conn = mysql_connect('yourdbhost', 'yourdbuser', 'yourdbpassword'); mysql_select_db('yourdbname', $db_conn); //query the db for each search term foreach($search_terms as $search_term) { //----slow but clear way---- $result = mysql_query("SELECT user_id FROM user WHERE EXISTS ( SELECT user_id FROM userinfo WHERE essay like '%{$search_term}%' AND user.user_id = userinfo.user_id)", $db_conn); //for eachr user id returned, delete them from your users table //as you would have done manually. I don't know about your users //table so you will have to edit this query as you see fit. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $user_del_result = mysql_query("DELETE FROM user WHERE user_id = {$row['user_id']} LIMIT 1", $db_conn); //might want to check here to see if the query executed successfully } //----faster way---- $result = mysql_query("DELETE FROM user WHERE EXISTS ( SELECT user_id FROM userinfo WHERE essay like '%{$search_term}%' AND user.user_id = userinfo.user_id)", $db_conn); } ?&gt; </code></pre> <p>To call it periodically you need to have a look at cron jobs (<a href="http://www.unixgeeks.org/security/newbie/unix/cron-1.html" rel="nofollow">read this</a>) and then just call the PHP script periodically with something like this in your crontab (this would run once per day at midnight for instance):</p> <pre><code>0 0 * * * /path/to/php-cli /path/to/the/above/php/file.php </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload