HTML_Table实现排序输出的问题

vwwdqw 2012-10-17 07:36:41
目的是希望使用某些条件(例如按价格)对信息排序。方法是通过链接列表头来实现,单击任何链接就会使用该表头作为条件对表数据进行排序。


<?php
require_once 'D:/xampp/php/pear/HTML/Table1.8.3/Table.php';

class corporate_mysqli extends mysqli {
function tabular_output($query) {
$attribute = array('border' => '1');

$table = new HTML_Table($attribute);
$result = $this->query($query);

$fieldInfo = $result->fetch_fields();

$colnum = 0;
foreach ($fieldInfo as $field) {
$header = '<a href="'.$_SERVER['PHP_SELF'].'?keyword='.$field->orgname.'&'.
$_SERVER['QUERY_STRING'].'">'.$field->name.'</a>';
$table->setHeaderContents(0, $colnum, $header);
$colnum++;
}

$rownum = 1;
$colnum = 0;
while (($row = $result->fetch_row()) == TRUE) {
while ($colnum < mysqli_field_count($this)) {
$table->setCellContents($rownum, $colnum, $row[$colnum]);
$colnum++;
}

$rownum++;
$colnum = 0;
}

echo $table->toHTML();
}
}



$sort = (isset($_GET['sort'])) ? $_GET['sort'] : "id";

$columns = array('id', 'order_time', 'sub_total', 'shipping_cost', 'total_cost');
if (in_array($sort, $columns)) {
$query = 'SELECT id AS "Order ID", client_id AS "Client ID", order_time AS "Order Time",'.
'CONCAT("$", sub_total) AS "Sub Total", CONCAT("$", shipping_cost) AS "Shipping Cost",'.
'CONCAT("$", total_cost) AS "Total Cost"'.
'FROM sales'.
'ORDER BY '.$sort.' ASC';
}
$mysqli = new corporate_mysqli('localhost', 'root', 'bmmepmhepb11619602VASQE', 'corporate');
$mysqli->tabular_output($query);
?>


为什么输出会显示:Fatal error: Call to a member function fetch_fields() on a non-object in D:\xampp\htdocs\Project\newfile2.php on line 11?
...全文
206 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
一起混吧 2012-10-17
  • 打赏
  • 举报
回复
sql 有错误
$query = 'SELECT id AS "Order ID", client_id AS "Client ID", order_time AS "Order Time",'.
'CONCAT("$", sub_total) AS "Sub Total", CONCAT("$", shipping_cost) AS "Shipping Cost",'.
'CONCAT("$", total_cost) AS "Total Cost"'.
' FROM sales '.
'ORDER BY '.$sort.' ASC';
vwwdqw 2012-10-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

我也发现了。。。
[/Quote]

那么。。。应该怎么回事啊。。这个问题
__phoenix 2012-10-17
  • 打赏
  • 举报
回复
我也发现了。。。
vwwdqw 2012-10-17
  • 打赏
  • 举报
回复
我又发错地方了,应该是PHP的HTML_Table

87,991

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧