gpt4 book ai didi

php - 无法从 sql 数据库中检索并设置值

转载 作者:行者123 更新时间:2023-11-30 22:28:25 25 4
gpt4 key购买 nike

我在 mysql 数据库中有这些表:

answer_det:

enter image description here

问题:

enter image description here

我想为属于特定项目的一个问题选择 4 个答案。每个问题都有一个 id(qid),每个项目都有一个 id(pid)。例如,我想选择属于 pid=2 qid=3 的每个答案。然后我想将检索到的值(答案)存储到输入文本字段中。这就是我要从“answer_det”表中检索的信息。

我想从“question”表中检索相同“pid”的 question_link 和

<?php

if (!empty($error_msg)) {
echo $error_msg;
}

$qid1 = $_POST['qid'];

$retrieve ="SELECT answer FROM answer_det AS answer1 WHERE pid = '" . $_SESSION['pid'] . "' AND qid ='$qid1' AND aid'1'";
$retrieve .="SELECT answer FROM answer_det AS answer2 WHERE pid = '" . $_SESSION['pid'] . "' AND qid ='$qid1' AND aid'2'";
$retrieve .="SELECT answer FROM answer_det AS answer3 WHERE pid = '" . $_SESSION['pid'] . "' AND qid ='$qid1' AND aid'3'";
$retrieve .="SELECT answer FROM answer_det AS answer4 WHERE pid = '" . $_SESSION['pid'] . "' AND qid ='$qid1' AND aid'4'";

$retrieve .="SELECT question_link FROM question WHERE pid = '" . $_SESSION['pid'] . "' AND qid ='$qid1'";

$result = $mysqli->multi_query($retrieve);

if ($result->num_rows > 0) {
while($row = $result->fetch_array()) {

echo "
<form action='insertdilemma.php' method='post'><br>

<h2>Dilemma</h2>

<div>Video link:<br><textarea rows='1' cols='40' name='videolink1'>". $row["question_link"]. "</textarea></div>

Svar 1: <input type='text' name='ans1' value='". $row["answer1"]. "'>
Svar 2: <input type='text' name='ans1' value='". $row["answer2"]. "'>
Svar 3: <input type='text' name='ans1' value='". $row["answer3"]. "'>
Svar 4: <input type='text' name='ans1' value='". $row["answer4"]. "'>

<input type='submit' name='submit' value='Create'>
</form>
";
}}

else {
echo "Wrong info.";
}

mysqli_close($mysqli);

?>

我得到这个错误:注意:第77行尝试获取C:\xampp\htdocs\wildfire\editdilemma.php中非对象的属性

这是哪一行:如果($result->num_rows > 0){

我做错了什么?

最佳答案

您应该能够首先使用如下简单的查询来修复错误:

$retrieve ="SELECT aid, answer FROM answer_det WHERE pid = '" . $_SESSION['pid'] . "' AND qid ='$qid1'";

然后您将得到每个答案作为结果,因此您必须更改 while 循环以正确地以 HTML 格式输出结果。

关于php - 无法从 sql 数据库中检索并设置值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34578992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com