Click to See Complete Forum and Search --> : Query help?


chrisb
06-19-2007, 08:13 AM
Hi All,

I’m running a query and after that query I want to run a thank you message:


$result = mysql_query("Insert into results(team_one_id ,team_two_id) values('$team_one_id''$team_two_id')");
$msg = "Thank you the fixture " . $team_one_id ." v's " . $team_two_id ." has been added to the database. Please continue or <a href='../index.php'>Return to the index </a>";


Now the data I enter in the database I want to be able to say find the values entered in the database ie: 1 v’s 2

And then lookup the values in the database in another table teams and print them in the thank you message:

So the thank you message would output as:

team a v's team b

teams

Team_id | Name
1 | Team A
2 | Team B

Now this is the code I have for doing this:


SELECT th.team_name AS home_team, ta.team_name As away_team, r.home_score, r.away_score, r.results_id
FROM results r
INNER JOIN teams th ON r.team_one_id = th.team_id
INNER JOIN teams ta ON r.team_two_id = ta.team_id


So how can I run my insert query whilst running the above at the same time to produce my thank you message?

jasonahoule
06-19-2007, 08:40 AM
I am not sure I really understand what you are saying here. You can execute more than one query.

chrisb
06-19-2007, 09:08 AM
Thanks,

so say in this query:


<?php

// Start the connection to the database
// Deleted!

// Include functions to get the various values from the dropdown boxes
include('../../../include/functions.php');

// ** If Submit is hit do your stuff **
if (isset($_POST['Submit'])) {

// ** Check for Required Fields with IF statements **
if (empty($team_one_id)){
$msg = "** You forgot to enter the home team! **";
} else if (empty($team_two_id)){
$msg = "** Error: You forgot to enter the away team! **";

// ** If all of the statements are true then **
} else {
$result = mysql_query("Insert into results(match_date,team_one_id,team_one_score,team_two_score,team_two_id,form,competition) values('$match_date','$team_one_id','$team_one_score','$team_two_score','$team_two_id','$form','$com petition')");
$msg = "Thank you the fixture " . $home_team ." v's " . $team_two_id ." has been added to the database. Please continue or <a href='../index.php'>Return to the index </a>";

}
}
?>


I want to run that query, but then also at the same time do a lookup on the teams table I mentioned to use this query:


SELECT th.team_name AS home_team, ta.team_name As away_team, r.home_score, r.away_score, r.results_id
FROM results r
INNER JOIN teams th ON r.team_one_id = th.team_id
INNER JOIN teams ta ON r.team_two_id = ta.team_id


Thanks

jasonahoule
06-19-2007, 09:46 AM
<?php

// Start the connection to the database
// Deleted!

// Include functions to get the various values from the dropdown boxes
include('../../../include/functions.php');

// ** If Submit is hit do your stuff **
if (isset($_POST['Submit'])) {

// ** Check for Required Fields with IF statements **
if (empty($team_one_id)){
$msg = "** You forgot to enter the home team! **";
} else if (empty($team_two_id)){
$msg = "** Error: You forgot to enter the away team! **";

// ** If all of the statements are true then **
} else {
$result = mysql_query("Insert into results(match_date,team_one_id,team_one_score,team_two_score,team_two_id,form,competition) values('$match_date','$team_one_id','$team_one_score','$team_two_score','$team_two_id','$form','$com petition')");
$result2 = mysql_query("SELECT th.team_name AS home_team, ta.team_name As away_team, r.home_score, r.away_score, r.results_id
FROM results r
INNER JOIN teams th ON r.team_one_id = th.team_id
INNER JOIN teams ta ON r.team_two_id = ta.team_id");
$msg = "Thank you the fixture " . $home_team ." v's " . $team_two_id ." has been added to the database. Please continue or <a href='../index.php'>Return to the index </a>";

}
}
?>