Jump to content

Running multiple sql Queries


millsy007

Recommended Posts

I am thinking of the best way of running a number of mysql queries depending on the value of a variable.

 

I need to fill in tables on my database that manages a coach timetable, where each coach/shuttle run has a number of journeys with in it.

For example a shuttle run between London and Moscow would incorporate the routes london to paris, paris to berlin ... etc

 

So if there is a shuttle going from London to Moscow it would mean that there are a number of journeys, each of which would need there own sql queries running.

The code below shows the sql I want to run, but I do not know how to logically break this up in code !?

 

 

i

f ($route==London To Moscow)
  {
  
//RUN A QUERY TO FIND DETAILS OF A PARTICULAR JOURNEY
$query = "
SELECT  journey.journey_id 
FROM 	shuttle, journey 
WHERE 	shuttle.id = journey.shuttle_id
and 	shuttle.depart_dttm = '$depart_dttm'
and	journey.route_id = 1
";

//GET THE JOURNEY ID
$journey_id = $row[journey_id ]

//PUT THE JOURNEY ID INTO THE PASSNGER TABLE TO SHOW THEY WILL BE ON THIS PART OF THE JOURNEY
INSERT INTO passengers ($name, $journey_id)


//RUN A QUERY TO FIND DETAILS OF THE NEXT JOURNEY THAT MAKES UP THE COMPLETE TRIP
$query = "
SELECT  journey.journey_id 
FROM 	shuttle, journey 
WHERE 	shuttle.id = journey.shuttle_id
and 	shuttle.depart_dttm = '$depart_dttm'
and	journey.route_id = 2
";

INSERT INTO passengers ($name, $journey_id)

}

 

What is a good way to organize this?

Link to comment
Share on other sites

<?php
if ($route==London To Moscow)
  {

//RUN A QUERY TO FIND DETAILS OF A PARTICULAR JOURNEY
$query = "
SELECT  journey.journey_id
FROM    shuttle, journey
WHERE    shuttle.id = journey.shuttle_id
and    shuttle.depart_dttm = '$depart_dttm'
and   journey.route_id = 1
";

mysql_query($query);

//GET THE JOURNEY ID
$journey_id = mysql_insert_id(); //$row[journey_id ]

/*
PUT THE JOURNEY ID INTO THE PASSNGER TABLE TO SHOW 
THEY WILL BE ON THIS PART OF THE JOURNEY 
INSERT INTO passengers ($name, $journey_id)
*/

/*RUN A QUERY TO FIND DETAILS OF THE NEXT 
JOURNEY THAT MAKES UP THE COMPLETE TRIP*/
$query = "
SELECT  journey.journey_id
FROM    shuttle, journey
WHERE    shuttle.id = journey.shuttle_id
and    shuttle.depart_dttm = '$depart_dttm'
and   journey.route_id = 2
";
mysql_query($query);
$journey_id = mysql_insert_id(); 
INSERT INTO passengers ($name, $journey_id)
   
}

?>

like that?

but this is not finish yet..

u must have control 4 above query.

if the 1st query FAIL is fine.. the data will not insert

if the 2nd query FAIL.. u must FAIL the 1st too

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.