count rows of specify table of current user

vipzeus

Member
I need the sum of total records filtered by $userid in the list of another table.
Im use calc element but does not work.
Here what i have:
PHP:
$db =& JFactory::getDBO();
$counter = "SELECT COUNT(*) AS id FROM pizzabook WHERE userid = '{$my->id}'";
$num = mysql_fetch_array($counter);
$count = $num["id"];
echo("$count");
 
using Joomla's db code....
PHP:
$db = JFactory::getDbo();
$user = JFactory::getUser();
$query = $db->getQuery(true);
$query->select('COUNT(*)')->from('pizzabook')->where('userid = ' . $user->get('id'));
$db->setQuery($query);
$count = $db->loadResult();
return $count;
 
ok, work for current logenin user.
In my list "pizzerie" i have userid element.
I need to show the sum of each userid in the row. so...

PHP:
$db = JFactory::getDbo();
$user = select('userid')->from('pizzerie')where ('id =' $rowid);
$query = $db->getQuery(true);
$query->select('COUNT(*)')->from('pizzabook')->where('userid = ' . $user->get('id'));
$db->setQuery($query);
$count = $db->loadResult();
return $count;

but as usually i have syntax errors. :rolleyes:
 
In my example $user->get('id') gets the current logged in user's id from the JUser object. You can't replace that with a query as you are trying to do in your example.

If the user id is present in the current row then you should just be able to use a placeholder?

PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')->from('pizzabook')->where('userid = ' .  (int) '{tablename___user_id_raw}');
$db->setQuery($query);
$count = $db->loadResult();
return $count;

replace the 'tablename___user_id' in 'tablename___user_id_raw' with your full element name.
 
The old donate button was a vBulletin forum add-on, which doesn't exist in the new XenForo forums.

We have a J! module we will probably enable some time soon.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top