Joel
Joel

Reputation: 2721

How do I make this UPDATE only work within this while loop?

I've been working on this for a couple days, and my brain has finally gone numb. My UPDATE is just updating every StartDate in the database, but I want it to only act on the event that is in the while loop this UPDATE is contained in. I think the code is probably fairly obvious, so here it is:

$query = "SELECT * FROM events WHERE ParentEventID='$tempParentEventID' AND GoogleID IS NULL";
$result = mysql_query($query);
            while($row = mysql_fetch_array($result, MYSQL_ASSOC)){

                $tempDaysFromEvent = $row['DaysFromEvent'];
                $tempStartDate = $row['StartDate'];

                //IF STARTDATE IS DIFFERENT FROM HOW IT USED TO BE, UPDATE IT.
                list($year, $month, $day) = explode("-", $tempStartDate);
                $tempStartDate      =   $tempEndDate    =    date("Y-m-d", mktime (0,0,0,$month,$day+$tempDaysFromEvent,$year));


                mysql_query("UPDATE".$eventDatabase." SET
                StartDate = '$tempStartDate'");


            }

I hope the above is clear enough. I am trying to change the StartDate in each $row as it goes through the loop.

Upvotes: 0

Views: 75

Answers (4)

Balanivash
Balanivash

Reputation: 6867

The query should be

 "UPDATE".$eventDatabase." SET  StartDate = '$tempStartDate' WHERE EventId =". $row['evenID'];

Upvotes: 2

Jacob
Jacob

Reputation: 43219

You need a WHERE-clause in your UPDATE-Statement to identify the row to be updated.

Upvotes: 1

oezi
oezi

Reputation: 51797

simply add a WHERE-clause to your update-statement:

UPDATE table SET StartDate = ... WHERE [whatever*]

*you havn't posted you table definitions, but it sounds like you should use your event-id here.

Upvotes: 1

Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

How about adding a where clause.

"UPDATE table SET field = '$sValue' WHERE eventID = ".$aRow['eventId']);

Upvotes: 6

Related Questions