在我的网站上,只有mysqli_fetch_assoc($ result)行。
$sql = "SELECT * FROM answers WHERE question_id = '$questionid' ORDER BY answer_id ASC";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
echo "<div>";
$answer = $row['answer'];
$userid = $row['user_id'];
$date = $row['answereddate'];
echo '<section style="height: 200px;">';
$username = $row['username'];
echo '<div class="answer-container">
<div id="description-container">';
echo $answer;
echo '</div>
</div>
<div class="profile-container">
<a>';
printDate($date);
echo '<br>';
echo '</a>
</div>
</section>';
echo "</div><br>";
}
仅打印answer 1
如果我在phpmyadmin中执行$ sql,则会得到2行:
答案 0 :(得分:-1)
为什么要使用数组?
$sql = "SELECT * FROM `answers` WHERE `question_id` = '12' ORDER BY `answer_id` ASC";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
$answer = $row['answer'];
echo $answer;
}