I have a couple of issues with the following code... Essentially, several values will need to be stored in $sqlBAnswer, but if I simply put [] after it, it saves the value "Array".
//Find the answer given by the user to the last answered question
$sqlB = mysql_query("SELECT Answer FROM Responses WHERE User = $sqlAPKID");
//If the operation produces an error, output an error message
if (!$sqlB) {
die('Invalid query for SQLB: ' . mysql_error());
}
//Count the number of rows output
$sqlBCount = mysql_num_rows($sqlB);
//If rows exist, define the values
if ($sqlBCount > 0) {
while ($row = mysql_fetch_array($sqlB)) {
$sqlBAnswer = $row["Answer"];
}
}
Assuming $sqlBAnswer did manage to hold multiple values, I then need to execute another query that will produce only one value (ie only one of the values stored in $sqlBAnswer will be in the result set.
I plan to do this using a foreach loop around the following code:
//Find the number of the next question to be answered based on the user's previous answer and the question they answered
$sqlC = mysql_query("SELECT NextQuestion FROM Answers WHERE QuestionNumber = $sqlALastQuestionAnswered AND PKID = $sqlBAnswer");
//If the operation produces an error, output an error message
if (!$sqlC) {
die('Invalid query for SQLC: ' . mysql_error());
}
//Count the number of rows output
$sqlCCount = mysql_num_rows($sqlC);
//If rows exist, define the values
if ($sqlCCount > 0) {
while ($row = mysql_fetch_array($sqlC)) {
$sqlCNextQuestion = $row["NextQuestion"];
}
}
What I need to have at the end is one value and one value only for sqlCNextQuestion, but I can't wrap my head around keys and values and whatnot, however much I read the documentation. If anyone could explain and show me how I could achieve what I'm after, I'd be very grateful!
Thanks :)
JOIN
in MySQL itself? – Ja͢ck Jan 29 '13 at 9:16