Hope some of you pros can help me out on this sql / php issue.
The short version:
I need to add members to a task-database. So I have memberlist, it loop through each member and runs below sql.
I need to run an SQL statement that is to exit after first update / execution where it hits the parameters. So I need some kind of return for each time the sql updates a field?
Pseudocode:
Update this column
condition 1
condition 2
after first execution exit
Current sql:
UPDATE calendar
SET spil1 = '$temp'
WHERE spil1 IS NOT NULL
AND
(dayname = 'Lørdag'
OR dayname = 'Søndag')
// now exit if the above is met and the sql update was executed.
So the problem is I cannot make it stop (tried limit, top etc)
How is this made with SQL? or is there a smart way to condition it in the PHP loop before executing the script?
3
Answers
Do you have an id column in calendar? If yes use the following query (Not tested):
What this query does, it brings the first record that applies to your condition, and then update that record the way you want it
if you are using any unique id put this code at the end of your query..
good luck.
I’m pretty sure you want to assign a different member to each
NULL
value in the calendar table. This is tricky. It requires enumerating the rows in each table for thejoin
— and assumes a unique id in the calendar table.I also suspect that you want the condition for the
calendar
table to beIS NULL
rather thanIS NOT NULL
, but this is the logic you have in the question.