[英]Doesn't show data on PHP but on workbench the SQL is correct
If I run the sql query on workbench, I can see the data.如果我在工作台上运行 sql 查询,我可以看到数据。 But on PHP there is nothing.
但是在 PHP 上什么都没有。 I found this part doesn't work.
我发现这部分不起作用。
echo '<ul><li>'.$title1.'</li>';
echo '<li>'.$content1.'</li>';
echo '<li>'.$answer1.'</li></ul>';
Does anyone know how to solve it?有谁知道如何解决它?
$qtitle =$_GET['id'];
$sql ="select Q1.title, Q1.content, Q1.answer from questionset_question as Q2";
$sql .=" inner join question as Q1 on Q1.question_id=Q2.question_id inner join questionset as Q3";
$sql .=" on Q3.questionset_id=Q2.questionset_id where Q3.title='$qtitle'";
if ($result = $db->query($sql)) {
while ($row = $result->fetch_assoc()) {
$title1=$row['Q1.title'];
$content1=$row['Q1.content'];
$answer1=$row['Q1.answer'];
echo '<ul><li>'.$title1.'</li>';
echo '<li>'.$content1.'</li>';
echo '<li>'.$answer1.'</li></ul>';
}
$result->free();
}
else {
echo "no result";
}
can you Try this way?你可以试试这个方法吗?
while ($row = $result->fetch_assoc()) {
$title1=$row['title'];
$content1=$row['content'];
$answer1=$row['answer']
Delete Q1 table name.删除 Q1 表名。 Because the result in pdo returns without table name.
因为 pdo 中的结果返回时没有表名。 MySQL workbench can list column name with table name.
MySQL 工作台可以列出列名和表名。
In PHP or other web applications it is always good idea to see the contents of the variable before proceeding ahead and displaying the data在 PHP 或其他 web 应用程序中,最好先查看变量的内容,然后再继续显示数据
Here I would use print_r()
function to see what $result
contains inside.在这里,我将使用
print_r()
function 来查看$result
包含的内容。
if ($result = $db->query($sql)) {
//check the value in $result.. used only for debugging
print_r($result);
exit('debugging');
while ($row = $result->fetch_assoc()) {
$title1 = $row['Q1.title'];
$content1 = $row['Q1.content'];
$answer1 = $row['Q1.answer'];
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.