It maybe something simple, but I keep trying and can't get it done. I'm using Joomla 3 with a mysql backend that has a custom made procedure (blogvote(i int)) which returns votes and assigns points based on vote - basically it is a simple code like this:
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`;
Then I use a custom made module with php code like this:
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');
It works now - i.e. I get the likes and points for a logged in user. I'd like to format it as a table - more or less like I have the output on phpmyadmin
Likes Points
3 0
And now I get something like this:
Array ( [] => stdClass Object ( [POINTS] => 0 [LIKES] => 3 ) )
How can I get a proper formatting if possible from php module file?
I tried some advice that was posted in comments. Right now I can display user_id in a table but the $result query produces an empty row:
echo "<table>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td>".$userval."</td>";
echo "</tr>";
echo "</table>";
foreach ($row as $result)
{
echo "<table>";
echo "<tr>";
echo "<td>" . $result->points . "</td>";
echo "<td>" . $result->likes . "</td>";
echo "</tr>";
echo "</table>";
}
Points = 0
andLikes = 3
?