php - How to update table when subsquery returns zero rowGet the solution ↓↓↓
Hello I have table of users and subscriptions.
I want to set event for subscription table once in day to update expired status when today date is greater than EndDate (See Table Below) For every line in subscription table.
UPDATE subscription SET status=expired WHERE EndDate>TODAY
And Want to Set event to update user table status to expired if there no rows found in given sub query because while login user i am only checking user status not check subscription table as it will take load on mysql database. Want set expiry on all users at night to update table base EndDate
UPDATE userstable SET status=expired WHERE IN (SELECT * FROM subscription WHERE status=active AND userid=1)
userid,fname,lname,email,status 1,john,jacob,[email protected],active 2,shelly,warden,[email protected],active
id,planID,userID,startDate,EndDate,Status 1,TRIAL,1,01/08/2020,07/08/2020,active 2,MONTHLY,2,03/08/2020,02/09/2020,active
I got answer to it..
UPDATE users SET status='expired' WHERE NOT EXISTS (SELECT * WHERE users.id=subscriptions.userID AND subscriptions.status='active')
it updates user table if there is not active plan for that user.
Share solution ↓
Link To Answer People are also looking for solutions of the problem: undefined array key php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.