Php $db->;loadObjectList和mysql_fetch_数组错误

Php $db->;loadObjectList和mysql_fetch_数组错误,php,joomla,Php,Joomla,我正在处理一个joomla模块,我为db连接编写了这段代码,然后从db中获取数据并将其打印到表中 $db = JFactory::getDBO(); $query = $db->getQuery(true); if($q == ""){ $query ->select(array('Stune_code,Stune_name,Stune_artist')) ->from('my_table') ->where('sub_cat_id = "4"')

我正在处理一个joomla模块,我为db连接编写了这段代码,然后从db中获取数据并将其打印到表中

 $db = JFactory::getDBO();
 $query = $db->getQuery(true);

 if($q == ""){

 $query
  ->select(array('Stune_code,Stune_name,Stune_artist'))
  ->from('my_table')
  ->where('sub_cat_id = "4"')
  ->limit('$start, $per_page');

$query_pag_data = $db->loadObjectList();

$msg = "<table class='show-rslt'><tr>
<th class='tbl-header'>Song Title</th>
<th class='tbl-header'>Artist</th>
<th class='tbl-header'>Code</th>
</tr>";
while ($row = mysql_fetch_array($query_pag_data)) {

$msg .= "<tr>";
$msg .= "<td class='title'>" . htmlentities($row['Stune_name']) . "</td>";
$msg .= "<td class='title'>" . htmlentities($row['Stune_artist']) . "</td>";
$msg .= "<td class='title'>" . htmlentities($row['Stune_code']) . "</td>";
$msg .= "</tr>";
}
$msg .= "</table>";
$msg = "<div class='data'><ul>" . $msg . "</ul></div>"; // Content for Data

我错在哪里?我应该怎么做才能得到正确的结果?您已经通过Joomla数据库对象加载了数据,因此无需再次尝试获取。只需对数组执行
foreach
循环即可

首先将调用更改为
loadAssocList()
(之所以需要,是因为您试图使用关联数组而不是对象来访问数据):

然后将循环更改为:

foreach($query_pag_data as $row) {
    $msg .= "<tr>";
    $msg .= "<td class='title'>" . htmlentities($row['Stune_name']) . "</td>";
    $msg .= "<td class='title'>" . htmlentities($row['Stune_artist']) . "</td>";
    $msg .= "<td class='title'>" . htmlentities($row['Stune_code']) . "</td>";
    $msg .= "</tr>";
}
foreach($query\u pag\u数据为$row){
$msg.=”;
$msg.=''.htmlentities($row['Stune_name']);
$msg.=''.htmlentities($row['Stune_artist']);
$msg.=''.htmlentities($row['Stune_code']);
$msg.=”;
}

Joomla数据库对象应用于所有数据库工作,不要尝试使用任何
mysql.*
函数。

此错误已被询问100万次。请快速搜索。可能是的副本
$query_pag_data = $db->loadAssocList();
foreach($query_pag_data as $row) {
    $msg .= "<tr>";
    $msg .= "<td class='title'>" . htmlentities($row['Stune_name']) . "</td>";
    $msg .= "<td class='title'>" . htmlentities($row['Stune_artist']) . "</td>";
    $msg .= "<td class='title'>" . htmlentities($row['Stune_code']) . "</td>";
    $msg .= "</tr>";
}