它可能很简单,但我一直在努力,无法完成它。我使用Joomla 3和一个mysql后端,后端有一个自定义程序(blogvote(i int)),它返回投票并根据投票分配点数 - 基本上它是一个简单的代码:
SELECT FLOOR(COUNT(`vote`)/10) AS POINTS, COUNT(`vote`) AS LIKES FROM `table1`, `table2` b
WHERE b.`id` = `item_id` AND b.`user_id` = p_user
AND `vote` = 1
GROUP BY b.`user_id`;
然后我使用一个自定义模块和php代码:
require JModuleHelper::getLayoutPath('mod_helloworld');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$user =& JFactory::getUser();
//display user name and user id
echo "<p>Your name is {$user->name} and your userid is {$user->id}</p>";
//get logged in user id to put into procedure call
$userval = $user->id;
//create query call to procedure
$query = "CALL blogvote($userval);";
$db->setQuery($query);
// $result = $db->query();
//print_r($result);
$row = $db->loadObjectList('user_id');
print_r($row);
require JModuleHelper::getLayoutPath('mod_helloworld');
它现在有效 - 即我获得了登录用户的喜欢和积分。我希望将其格式化为表格 - 或多或少像我在phpmyadmin上的输出
喜欢积分
3 0
现在我得到这样的东西:
Array ( [] => stdClass Object ( [POINTS] => 0 [LIKES] => 3 ) )
如果可能,我如何从php模块文件中获得正确的格式?