This topic is locked
[SOLVED]

 Updating next record in table that meets the criteria

2/29/2012 7:33:31 PM
PHPRunner General questions
C
copper21 author

Hello,
I am kind of stuck here. What I am trying to do is update the next record in line that meets the criteria using "update" on the edit page: After reord updated. If a user removes themselves from somthing that they have signed up for, I would like to change the status of the next person automatically. If someone has signed up for a class and has done so before the class is full, they get a "Pending" status. If someone signs up for a class after the class is full, they get a "On Waiting List" status. What I want to do is if someone in "Pending" status withdraws from the class, the update will then change the status of the next person in "On Waiting List" status to "Pending"
The first code will set the person who is in who changed themselves to withdrawn status from Pending status...works perfectly.
I need the next code to then set the next person in line with the "On Waiting List" status to "Pending" status, and ONLY 1 AT A TIME per occurrance. The second code works great, but does everyone in "On Waiting List" status. I tried using LIMIT 1 in the statement but got errors.
//Update sign-up Status to "Sign-up Withdrawn" if "sign-up withdrawn" is chosen
global $conn;

$sql = "UPDATE training_student_signup SET signed_up = '0', student_class_link = '".$values["student_class_link"]."', signup_status = 'Sign-up Withdrawn', approval_status = 'Sign-up Withdrawn' WHERE signup_status = 'Sign-up Withdrawn' AND studentid = '".$values["studentid"]."'";

CustomQuery($sql);
global $conn;

$sql = "UPDATE training_student_signup SET signed_up = '1', student_class_link = '".$values["student_class_link"]."', signup_status = 'Pending', approval_status = 'Pending' WHERE signup_status = 'On Waiting List'";

CustomQuery($sql);
Is there a way to do this?
Thanks!
Brian

C
copper21 author 3/1/2012

I was able to do what I wanted by using "TOP (1)" in my update statement.
//Update sign-up Status to "Sign-up Withdrawn" if "sign-up withdrawn" is chosen
global $conn;

$sql = "UPDATE training_student_signup SET signed_up = '0', student_class_link = '".$values["student_class_link"]."', signup_status = 'Sign-up Withdrawn', approval_status = 'Sign-up Withdrawn' WHERE signup_status = 'Sign-up Withdrawn' AND studentid = '".$values["studentid"]."'";

CustomQuery($sql);
//Select next user to Pending status if in "On Waiting List"
global $conn;

$sql = "UPDATE TOP (1) training_student_signup SET signed_up = '1', student_class_link = '".$values["student_class_link"]."', signup_status = 'Pending', approval_status = 'Pending' WHERE signup_status = 'On Waiting List'";

CustomQuery($sql);