我对以下代码有几个问题......基本上,需要将几个值存储在$sqlBAnswer中,但如果我只是将[]放在它之后,它会保存值"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"];
}
}
假设$sqlBAnswer确实设法保存了多个值,那么我需要执行另一个查询,该查询将只产生一个值(即只有一个存储在$sqlBAnswer中的值会在结果集中。
我计划使用围绕以下代码的foreach循环来执行此操作:
//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"];
}
}
最后我需要的是一个值,一个值仅用于sqlCNextQuestion,但我无法围绕键和值等等,无论我阅读了多少文档。如果有人能解释并告诉我如何实现我所追求的,我将不胜感激!
谢谢 :)