question
ドロップダウン メニューから選択したオプションに応じて結果を表示する mysqli/php コードを以下に示します。
$selectedquestionqry = "
SELECT
QuestionNo
FROM
Question
WHERE
(QuestionId = ?)
";
global $mysqli;
$selectedquestionstmt=$mysqli->prepare($selectedquestionqry);
// You only need to call bind_param once
$selectedquestionstmt->bind_param("i",$_POST["question"]);
// get result and assign variables (prefix with db)
$selectedquestionstmt->execute();
$selectedquestionstmt->bind_result($selQuestionNo);
$selectedquestionstmt->store_result();
$selquestionnum = $selectedquestionstmt->num_rows();
while ($selectedquestionstmt->fetch()) {
if($_POST["question"] === '0') {
echo "<p>All Questions - Total:(" . $selquestionnum . ")</p>" . PHP_EOL;
}else if($_POST["question"] !== '0') {
echo "<p><strong>Questions: </strong>" . $selQuestionNo . "</p>" . PHP_EOL;
}
}
ドロップダウンメニュー:
<select name="student" id="studentsDrop">
<option value="0">All</option>
<option value="23">Jay Hart</option>
<option value="32">Bubba Wright</option>
</select>
question
私の質問は、ユーザーが「0」を選択した場合、ドロップダウンメニューに表示されるデータベースからすべての質問を選択できるようにするにはどうすればよいですか?
これを尋ねている理由は、私の echoelse if($_POST["question"] !== '0') {
echo "<p><strong>Questions: </strong>" . $selQuestionNo . "</p>" . PHP_EOL;
}
では、オプションを選択しても何もエコーさAll
れていないためです。これにより、エコーが表示されていないと思います。ドロップダウン メニューから 1 つの質問を選択すると、エコーを出力できます。