I’m in a deep s**t and need help from smart fellows like you.
Here is some info about software and technologies I use: cPanel, Linux server, phpMyAdmin, MySQL.
I need to delete some records from a table on a daily basis. I do it normally by using Select statement on phpMyAdmin and then delete all the records.
*
Select `user_id` FROM `user`
WHERE EXISTS ( SELECT `user_id`
FROM `userinfo`
WHERE `essay` like '% yahoo %' AND user.user_id = userinfo.user_id)
*
The above code basically searches for specific words in userinfo table and displays their corresponding user_id in user table, which I then delete manually. In this particular case the search term is ‘yahoo’. I search for all the users who have the word ‘yahoo’ in their profile’s essay and delete them from user table.
The problem is I’ve got way too many search terms to do it manually.
I would love to have it written in php file and run through cron if it’s possible. Would be nice to have a field or fields on php file where I would type all possible search words/phrases then the code would execute all of them one after another.
I’ve heard it’s possible to use cron jobs for that, read some articles about them but have absolutely no idea how to handle it.
Your help would be much appreciated and please tell me if it’s unclear.
Regards,
Igor
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 by FAR 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 untested 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.
PHP script to do what you want:
To call it periodically you need to have a look at cron jobs (read this) 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):