Jump to content

update 1 table compare 2 tables query


knightsjoker

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.