knightsjoker Posted February 2, 2009 Share Posted February 2, 2009 Hi guys, I'm stump on how to do this. Basically I'm trying to update 1 table by comparing values from different tables. here's how i set it up: $query = "SELECT booking_event.starting_date_time, booking_schedule.schedule_date_time ". "FROM booking_event, booking_schedule ". "WHERE booking_event.starting_date_time = booking_schedule.schedule_date_time"; with that part set... i want to update a different field which is event_id_location_# (there are 20 locations) I want to update just certain location according to the schedule_date_time so let's say location 1 has a value of 1 (occupied) I want to update it to 0 (not occupied) how do I go about doing this? I already passed the hidden value of location (is it correct?): <a href=\"delete.php?id={$row[id]}&passlocation={$getlocation}\">Delete</a>"; ?> I was thinking of if function. while($row = mysql_fetch_array($query)) { if (location == loc1) { $query2="UPDATE booking_schedule SET event_id_location_1 = '0'"; } } thanks guys Link to comment https://forums.phpfreaks.com/topic/143420-update-1-table-compare-2-tables-query/ Share on other sites More sharing options...
premiso Posted February 2, 2009 Share Posted February 2, 2009 Why not just do this: if (isset($_GET['passlocation'])) { mysql_query("UPDATE booking_schedule SET event_id_location_" . (int) $_GET['passlocation'] . " = '0' WHERE id = '" . (int) $_GET['id'] . "'"); } I would suggest doing data checks on the $_GET, but yea. In the one you posted, without the where, every row in that table would be set to 0. Link to comment https://forums.phpfreaks.com/topic/143420-update-1-table-compare-2-tables-query/#findComment-752319 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.