PDA

View Full Version : Double Query


SmEdD
12-02-2003, 01:56 AM
Is there a way to keep from having to run the same query 2 times?

$games = $DB_site->query("
SELECT *
FROM " . TABLE_PREFIX . "clan_game
ORDER BY displayorder
");

while ($game = $DB_site->fetch_array($games))
{
globalize($_POST, array("game_$game[gameid]", "game_$game[gameid]" . '_opt'));
$gamenames .= ', roster.game_' . $game['gameid'];
}
unset($game);
unset($games);

$memberinfo = $DB_site->query_first("
SELECT
roster.memberid, roster.callsign, roster.firstname, roster.lastname, roster.birthday, roster.rank, roster.email, roster.status, roster.location,
rank.title$gamenames
FROM " . TABLE_PREFIX . "clan_roster AS roster
LEFT JOIN " . TABLE_PREFIX . "clan_rank AS rank ON(rank.level = roster.rank)
WHERE roster.memberid = $memberid
");

// Generate Games
$games = $DB_site->query("
SELECT *
FROM " . TABLE_PREFIX . "clan_game
ORDER BY displayorder
");
while ($game = $DB_site->fetch_array($games))
{
$name = 'game_' . $game['gameid'];
if ($memberinfo["$name"] == 1)
{
$memberinfo['games'] .= $game['title'] . '<br />';
}
}

Issvar
12-02-2003, 05:36 AM
Is there a way to keep from having to run the same query 2 times?

$games = $DB_site->query("
SELECT *
FROM " . TABLE_PREFIX . "clan_game
ORDER BY displayorder
");

while ($game = $DB_site->fetch_array($games))
{
globalize($_POST, array("game_$game[gameid]", "game_$game[gameid]" . '_opt'));
$gamenames .= ', roster.game_' . $game['gameid'];

//Generate games
$name = 'game_' . $game['gameid'];
if ($memberinfo["$name"] == 1)
{
$memberinfo['games'] .= $game['title'] . '<br />';
}
}
unset($game);
unset($games);

$memberinfo = $DB_site->query_first("
SELECT
roster.memberid, roster.callsign, roster.firstname, roster.lastname, roster.birthday, roster.rank, roster.email, roster.status, roster.location,
rank.title$gamenames
FROM " . TABLE_PREFIX . "clan_roster AS roster
LEFT JOIN " . TABLE_PREFIX . "clan_rank AS rank ON(rank.level = roster.rank)
WHERE roster.memberid = $memberid
");

Dean C
12-02-2003, 11:01 AM
vb3 hacking discussion is not allowed here - please wait until RC1 as we've stated on many occasions prior to this :) Thanks