我正在尝试使用mysqli_query
但是当我想显示order by title
时,会显示以下内容
'order clause'中的未知列'title'
删除order by title
后,就可以了
上下文代码
<?php
include "database_conn.php";
$sqlEvent = "SELECT * FROM te_events ORDER BY title"; //the problem is here
//query the statement
$event= mysqli_query ($conn , $sqlEvent)
or die (mysqli_error($conn));
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title> Select Event </title>
<meta charset="utf-8">
</head>
<body>
<h1>Select Event</h1>
<table border = "1">
<thead>
<th>Title</th>
</thead>
<?php
//display all the event record
while ($row = mysqli_fetch_assoc ($event)){
//extract the field
$id = $row["eventID"];
$title = $row["eventTitle"];
//start a row
echo"<tr>\n";
//output the URL
echo "<td>\n";
echo "<div> <a href = \"viewEventDetails.php?eventTitle=$title\">
$title</a>\n";
echo "</td>\n";
}
?>
</table>
</body>
</html>
<?php
mysqli_close($conn);
?>
有关如何按标题显示数据的任何建议将不胜感激。
答案 0 :(得分:4)
从title
替换为eventTitle
,因为您的$行表示
$sqlEvent = "SELECT * FROM te_events ORDER BY eventTitle"; //
答案 1 :(得分:4)
查看处理结果集的代码我会说如果你改变了这个
$sqlEvent = "SELECT * FROM te_events ORDER BY title";
到此
$sqlEvent = "SELECT * FROM te_events ORDER BY eventTitle";
它可能会起作用
答案 2 :(得分:3)
修改强>
将行更改为:
$sqlEvent = "SELECT * FROM te_events ORDER BY eventTitle";
ORDER BY
之后的单词需要是数据库te_events
表中的字段。
根据你所说的$title = $row["eventTitle"];
后面的陈述来判断,eventTitle
是你在ORDER BY
条款中使用的内容。
答案 3 :(得分:3)
试试这个$sqlEvent = "SELECT * FROM te_events ORDER BY eventTitle";
答案 4 :(得分:1)
将标题替换为eventTitle,这是您的错误,实际的列名是eventTitle
$title = $row["eventTitle"];
$sqlEvent = "SELECT * FROM te_events ORDER BY eventTitle";