Ik heb een tabel met: quests: quest_id, quest_town_id, quest_members
en questing: questing_id, questing_quest_id, questing_user_id, questing_part, questing_done
Nu moet ik voor elkaar zien te krijgen (als dit mogelijk is met) om met JOINS samen te laten werken. Hij moet de QUESTING voortgang van de gebruiker (questing_user_id) koppelen aan de quest uit de het database.
Dus we hebben bijvoorbeeld user_id 22 en quest_id 3, nu zal me query de questing gegevens moeten ophalen voor de overeenkomende questing_user_id en questing_quest_id. Hoe doe ik dit? Want wat ik nu probeer gaat niet werken..
<?PHP
# Get the available quests for the town in question.
$sQuery = "SELECT quest_id, quest_members
FROM quests
INNER JOIN questing
ON (quest_id = questing_quest_id)
WHERE quest_town_id = " . $asTowns['town_id'] . "
AND questing_user_id = " . $_SESSION['user_id'];
$qSelQuests = mysql_query ($sQuery) or ($cMySQL -> mysql_error_handler ($sPart, $sFile, $sQuery, mysql_error ()));
while ($asQuests = mysql_fetch_assoc ($qSelQuests))
{
//verder...
}
?>
<?PHP
# Get the available quests for the town in question.
$sQuery="SELECT quest_id, quest_members
FROM quests
INNER JOIN questing
ON (quest_id = questing_quest_id)
WHERE quest_town_id = ".$asTowns['town_id']."
AND questing_user_id = ".$_SESSION['user_id'];
$qSelQuests=mysql_query($sQuery) or ($cMySQL->mysql_error_handler($sPart,$sFile,$sQuery,mysql_error()));
<?PHP
# Get the available quests for the town in question.
$sQuery = "SELECT
quests.quest_id,
quests.quest_members
FROM
quests
LEFT JOIN
questing
ON (quests.quest_id = questing.questing_quest_id)
WHERE quests.quest_town_id = " . $asTowns['town_id'] . "
AND questing.questing_user_id = " . $_SESSION['user_id'];
$qSelQuests = mysql_query ($sQuery) or ($cMySQL -> mysql_error_handler ($sPart, $sFile, $sQuery, mysql_error ()));
while ($asQuests = mysql_fetch_assoc ($qSelQuests))
{
//verder...
}
?>
<?PHP
# Get the available quests for the town in question.
$sQuery="SELECT
quests.quest_id,
quests.quest_members
FROM
quests
LEFT JOIN
questing
ON (quests.quest_id = questing.questing_quest_id)
WHERE quests.quest_town_id = ".$asTowns['town_id']."
AND questing.questing_user_id = ".$_SESSION['user_id'];
$qSelQuests=mysql_query($sQuery) or ($cMySQL->mysql_error_handler($sPart,$sFile,$sQuery,mysql_error()));
Marten, je bent top!
Dit is het geworden, en het werkt prima.. Nu snap ik ook weer wat meer van JOINS, want dat zal ik zeker vaker nodig gaan hebben met dit project. Dank je wel!
<?PHP
# Get the available quests for the town in question.
$sQuery = "SELECT
quests.quest_id,
quests.quest_members,
questing.questing_quest_id,
questing.questing_part,
questing.questing_done
FROM
quests
LEFT JOIN
questing
ON (quests.quest_id = questing.questing_quest_id)
WHERE quests.quest_town_id = " . $asTowns['town_id'] . "
AND questing.questing_user_id = " . $_SESSION['user_id'];
$qSelQuests = mysql_query ($sQuery) or ($cMySQL -> mysql_error_handler ($sPart, $sFile, $sQuery, mysql_error ()));
while ($asQuests = mysql_fetch_assoc ($qSelQuests))
{
//verder...
}
?>
<?PHP
# Get the available quests for the town in question.
$sQuery="SELECT
quests.quest_id,
quests.quest_members,
questing.questing_quest_id,
questing.questing_part,
questing.questing_done
FROM
quests
LEFT JOIN
questing
ON (quests.quest_id = questing.questing_quest_id)
WHERE quests.quest_town_id = ".$asTowns['town_id']."
AND questing.questing_user_id = ".$_SESSION['user_id'];
$qSelQuests=mysql_query($sQuery) or ($cMySQL->mysql_error_handler($sPart,$sFile,$sQuery,mysql_error()));