0

Everything here is working except the UPDATE command... The INSERT works fine but alas, I'm stuck.

$queryLastDateArray = "SELECT date FROM schedule ORDER BY ID DESC LIMIT 1";
$lastDateArray = mysql_query($queryLastDateArray);
while($row = mysql_fetch_array($lastDateArray))
                        {
                        $lastDate = $row['date'];
                        }                       
$lastDatePlusOne = date("Y-m-d", strtotime("+1 day", strtotime($lastDate)));

$newDatesArray = GetDays($lastDatePlusOne, $_POST[date]);
$i = 0;
while($i < count($newDatesArray))
        {
        if ((date('D', strtotime($newDatesArray[$i]))) == 'Fri')
                {
                $insDate = "INSERT INTO schedule (date) VALUES ('$newDatesArray[$i]')";
                $result = mysql_query($insDate);
                $insEmp = "UPDATE schedule SET schedule.jakes = schedule_default.jakes FROM schedule, schedule_default WHERE schedule.date = '$newDatesArray[$i]' AND schedule_default.ID = '5'";
                $result2 = mysql_query($insEmp);
                }
        $i++;
        }
3
  • Never use again count in the for/while line. Put in a variable and use the variable itself. Commented Apr 22, 2011 at 19:39
  • @Pentium10 - Why not? Is there a reason besides unnecessary micro-optimization? Commented Apr 22, 2011 at 19:47
  • For low-latency response time. Commented Apr 22, 2011 at 19:55

2 Answers 2

2

Try writing the update like this:

 "UPDATE schedule SET schedule.jakes = (SELECT schedule_default.jakes FROM  schedule_default WHERE schedule.date = '$newDatesArray[$i]' AND schedule_default.ID = '5')";
Sign up to request clarification or add additional context in comments.

Comments

1

Multiple table UPDATE syntax is:

UPDATE schedule, schedule_default
SET schedule.jakes = schedule_default.jakes
WHERE schedule.date = '$newDatesArray[$i]'
  AND schedule_default.ID = '5'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.