first off, why acquiring the team data from the database twice? I think you're better off loading the entire data in an array and then process it.
while (list($home_id, $home_name) = $db->sql_fetchrow($homelist)) {
if(isset($row['home']) && !empty($row['home']))
{
$sel = ($row['home'] == $home_id) ? 'selected' : '';
} else {
$sel = ($row['home'] == $home_name) ? 'selected' : '';
}
$ddhome[] = "echo '<option $sel value=$home_id>$home_name</option>\n'";
$team_data[] = $row; // added line
}
and the next should be replaced with
reset ($team_data);
do {
list($away_id, $away_name) = current ($team_data)
if(isset($row['away']) && !empty($row['away']))
{
$sel = ($row['away'] == $away_id) ? 'selected' : '';
} else {
$sel = ($row['away'] == $away_name) ? 'selected' : '';
}
$ddaway[] = "echo '<option $sel value=$away_id>$away_name</option>\n'";
} while (next ($team_data));
now if you want to execute only one query, what you need to look at is mysqli_multi_query(). I can't suggest a code because I don't know it too well, tho