如何使用原生Joomla 2.5 php对象显示Joomla数据库表

如何使用原生Joomla 2.5 php对象显示Joomla数据库表,php,mysql,class,object,joomla,Php,Mysql,Class,Object,Joomla,我试图使用原生joomla PHP对象显示MySQL数据库表中的数据,但是我永远无法让它正常工作。它从不显示任何数据 我知道如何通过旧的方式连接到数据库来显示数据,如下所示 $con = mysqli_connect("localhost","xxxxxx_user10","$dbpass","xxxxxxx_final"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: "

我试图使用原生joomla PHP对象显示MySQL数据库表中的数据,但是我永远无法让它正常工作。它从不显示任何数据

我知道如何通过旧的方式连接到数据库来显示数据,如下所示

$con = mysqli_connect("localhost","xxxxxx_user10","$dbpass","xxxxxxx_final");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
//What is the base model
$sku = $finish;
// Select The Correct Table
$result = mysqli_query($con,"SELECT * FROM BAH_finish WHERE color_value='$sku' GROUP BY uniqueID ORDER BY uniqueID ASC");
  $row = mysqli_fetch_array($result);
  $finishname = $row['color_name'];
  $finishtype = $row['color_type'];
然而,我希望像上面一样显示内容,但是通过使用joomla原生php对象,因此iv'e创建了一个带有以下字段的示例php表

| ID | Last | First | Address | City | State | ZIP
并尝试使用以下joomla代码显示所有行/或一行…但什么都没有发生…无论我如何尝试将其切换或更改部分代码…因此我的想法是,我缺少了这应该如何工作的基本部分…再次感谢您的帮助!另外,请不要引用joomla.org上的joomla 2.5组件教程……这就是我得到这段代码的地方,在我看来,它缺少很多信息

<?php

// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('Last', 'First', 'Address', 'City', 'State', 'ZIP')));
$query->from($db->quoteName('111testnames'));
$query->where($db->quoteName('Last') . $db->quote('buffet'));

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadObjectList();

echo $results;

?>
您必须更正:$query->from$db->quoteName'111testnames'

到$query->from$db->quoteName“测试名称”

使用_u会自动添加表的后缀

我可以看到的另一个错误是where子句没有运算符。请尝试将其更正为$query->where$db->quoteName'Last'。=$db->引用“自助餐”

为了正确查看结果,您必须使用print_r$results;而不是结果;因为有一个对象数组,所以必须显示而不是字符串

祝你好运