我正在尝试使用joomla管理员中的列名对表数据进行排序。但是当我尝试使用连接表中的列对表进行排序时,它会产生如下错误
500 - An error has occurred.
Champ 'a.product_name' inconnu dans order clause SQL=SELECT a.*,created_by.name AS created_by FROM `jos_alphabatic_formdata` AS a LEFT JOIN jos_users AS created_by ON created_by.id = a.created_by ORDER BY a.product_name asc Champ 'a.product_name' inconnu dans order clause SQL=SELECT a.*,created_by.name AS created_by FROM `jos_alphabatic_formdata` AS a LEFT JOIN jos_users AS created_by ON created_by.id = a.created_by ORDER BY a.product_name asc LIMIT 0, 20 Champ 'a.product_name' inconnu dans order clause SQL=SELECT a.*,created_by.name AS created_by FROM `jos_alphabatic_formdata` AS a LEFT JOIN jos_users AS created_by ON created_by.id = a.created_by ORDER BY a.product_name asc
这是我生成表格的文件:
<table class="adminlist">
<thead>
<tr>
<th width="1%">
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'COM_ALPHABATIC_FORMDATAS_ORDER_ID', 'a.order_id', $listDirn, $listOrder); ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'COM_ALPHABATIC_FORMDATAS_CATEGORY_ID', 'a.category_id', $listDirn, $listOrder); ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Product Name', 'a.product_name', $listDirn, $listOrder); ?>
<?php //echo "Product Name"; ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Created On', 'a.created_on', $listDirn, $listOrder); ?>
<?php// echo "Created On"; ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Order Status', 'a.order_status', $listDirn, $listOrder); ?>
<?php //echo "Order Status"; ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'Email', 'a.email', $listDirn, $listOrder); ?>
<?php // echo "Email" ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Item Price', 'a.item_price', $listDirn, $listOrder); ?>
<?php //echo "Item Price"; ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Saved', 'a.saved', $listDirn, $listOrder); ?>
<?php //echo "Saved"; ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Validated', 'a.validated', $listDirn, $listOrder); ?>
<?php //echo "Validated"; ?>
</th>
<th class='left'>
<?php echo JHtml::_('grid.sort', 'Last Modified', 'a.last_modified', $listDirn, $listOrder); ?>
<?php //echo "Last Modified"; ?>
</th>
<!-- <th class='left'>
<?php //echo JHtml::_('grid.sort', 'COM_ALPHABATIC_FORMDATAS_DATA', 'a.data', $listDirn, $listOrder); ?>
</th> -->
<th class='left'>
<?php echo JHtml::_('grid.sort', 'COM_ALPHABATIC_FORMDATAS_CREATED_BY', 'a.created_by', $listDirn, $listOrder); ?>
</th>
<?php if (isset($this->items[0]->state)) { ?>
<th width="5%">
<?php echo JHtml::_('grid.sort', 'JPUBLISHED', 'a.state', $listDirn, $listOrder); ?>
</th>
<?php } ?>
<?php if (isset($this->items[0]->ordering)) { ?>
<th width="10%">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ORDERING', 'a.ordering', $listDirn, $listOrder); ?>
<?php if ($canOrder && $saveOrder) :?>
<?php echo JHtml::_('grid.order', $this->items, 'filesave.png', 'formdatas.saveorder'); ?>
<?php endif; ?>
</th>
<?php } ?>
<?php if (isset($this->items[0]->id)) { ?>
<th width="1%" class="nowrap">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.id', $listDirn, $listOrder); ?>
</th>
<?php } ?>
</tr>
</thead>
<tfoot>
<?php
if(isset($this->items[0])){
$colspan = count(get_object_vars($this->items[0]));
}
else{
$colspan = 10;
}
?>
<tr>
<td colspan="<?php echo $colspan ?>">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item) :
$ordering = ($listOrder == 'a.ordering');
$canCreate = $user->authorise('core.create', 'com_alphabatic');
$canEdit = $user->authorise('core.edit', 'com_alphabatic');
$canCheckin = $user->authorise('core.manage', 'com_alphabatic');
$canChange = $user->authorise('core.edit.state', 'com_alphabatic');
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php echo $item->order_id; ?>
</td>
<td>
<?php echo $item->category_id; ?>
</td>
<?php $this->getproductdata($item->order_id); ?>
<td>
<?php echo $this->item_name; ?>
</td>
<td>
<?php echo $this->created_on; ?>
</td>
<td>
<?php echo $this->order_status; ?>
</td>
<td>
<?php echo $this->get_email; ?>
</td>
<td>
<?php echo $this->product_price; ?>
</td>
<?php
$data_1 = json_decode($item->data);
$data_2 = (array) $data_1;
$c1 = array();
foreach($data_2 as $key1 => $value1)
{
$c1[] = $value1->status;
}
$c2 = implode(',',$c1);
$saved_count = substr_count($c2, 's');
$validated_count = substr_count($c2,'v');
?>
<td>
<?php echo $saved_count; ?>
</td>
<td>
<?php echo $validated_count; ?>
</td>
<td>
<?php echo $this->get_modified; ?>
</td>
<!-- <td>
<?php //echo $item->data; ?>
</td> -->
<td>
<?php echo $item->created_by; ?>
</td>
<?php if (isset($this->items[0]->state)) { ?>
<td class="center">
<?php echo JHtml::_('jgrid.published', $item->state, $i, 'formdatas.', $canChange, 'cb'); ?>
</td>
<?php } ?>
<?php if (isset($this->items[0]->ordering)) { ?>
<td class="order">
<?php if ($canChange) : ?>
<?php if ($saveOrder) :?>
<?php if ($listDirn == 'asc') : ?>
<span><?php echo $this->pagination->orderUpIcon($i, true, 'formdatas.orderup', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, true, 'formdatas.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
<?php elseif ($listDirn == 'desc') : ?>
<span><?php echo $this->pagination->orderUpIcon($i, true, 'formdatas.orderdown', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, true, 'formdatas.orderup', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
<?php endif; ?>
<?php endif; ?>
<?php $disabled = $saveOrder ? '' : 'disabled="disabled"'; ?>
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering;?>" <?php echo $disabled ?> class="text-area-order" />
<?php else : ?>
<?php echo $item->ordering; ?>
<?php endif; ?>
</td>
<?php } ?>
<?php if (isset($this->items[0]->id)) { ?>
<td class="center">
<?php echo (int) $item->id; ?>
</td>
<?php } ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
当我尝试单击product_name列时调用此函数。当我尝试使用字母表格数据表中的列进行排序时,它可以工作,如下所示
protected function getListQuery() {
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select', 'a.*'
)
);
$query->from('`#__alphabatic_formdata` AS a');
// Join over the user field 'created_by'
$query->select('created_by.name AS created_by');
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where('a.id = ' . (int) substr($search, 3));
} else {
$search = $db->Quote('%' . $db->escape($search, true) . '%');
}
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
if ($orderCol && $orderDirn) {
$query->order($db->escape($orderCol . ' ' . $orderDirn));
}
return $query;
}
任何人都可以帮我解决这个问题吗?如何使用查询的连接部分中的列进行排序?