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);";
    // $result = $db->query();
    $row = $db->loadObjectList('user_id');
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>";
  • Are you trying to just display the results, e.g Points = 0 and Likes = 3?
    – Lodder
    Commented Sep 27, 2015 at 17:47
  • I want to display the results as a table with a 2 rows and 2 columns just like what the procedure generates in phpmyadmin. So top row would be: Points Likes and bottom row would be number of points/likes so: 0 and 3 (below Likes)
    – aretai
    Commented Sep 27, 2015 at 18:04

1 Answer 1


You can display the results in a table and use a foreach loop for the actual results, like so:

        foreach ($row as $result) 
            echo '<tr>';        
            echo '<td>' . $result->POINTS. '</td>';
            echo '<td>' . $result->LIKES . '</td>';
            echo '</tr>';
  • I tried something similar - check my question edit, but it didn't produce result table but instead an empty table row:(
    – aretai
    Commented Sep 27, 2015 at 20:45
  • @aretai - Can you try $result->POINTS instead of $result->points
    – Lodder
    Commented Sep 27, 2015 at 21:17
  • Yes it is working now +rep
    – aretai
    Commented Sep 27, 2015 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.