Jump to content

Query code needs some tweaking...


BelowZero

Recommended Posts

I'm putting some code that works with one database into a new website. Problem is the 2nd database has a bit of a different structure than the 1st so I need to make some changes.

In the 1st database, I'm calling 2 different values that are contained in 1 row.

In the 2nd database, I'm trying to call 2 values, but they are in different rows so I need to change my SELECT statement.

 

This is the code that works in database 1:

$result = mysql_query("
SELECT S.game_id, TH.team_name AS HomeTeam, TA.team_name AS AwayTeam
FROM schedule AS S 
JOIN teams AS TH ON S.team = TH.team_id
JOIN teams AS TA ON S.team = TA.team_id
WHERE S.week_id = '$weekID'
ORDER BY S.game_id;");

while ($row = mysql_fetch_array($result)) {
printf('<input type="text" size="4" name="spread[%d][%d][A]">', $weekID, $row['game_id']);
printf(" %s vs. %s ", $row['AwayTeam'], $row['HomeTeam']);
printf('<input type="text" size="4" name="spread[%d][%d][H]">', $weekID, $row['game_id']);
} 

 

The 2nd database has one field to hold the team name and another field (place_id) to hold a single letter (H or A) to signify whether a team is Home or Away. (the 1st database has "A_team" and "H_team" fields in the same row.) They both use the tables "teams" and "schedule".

 

Can I alter this code to look at 2 rows (place_id="H" and place_id="A") for the values without having to create 2 queries? Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/229643-query-code-needs-some-tweaking/
Share on other sites

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.