mysql - Retrieving mutiple row data from sql by php executed under joomla -
i have sql query working fine. after execution (php form in joomla inserted sourcerer plugin) resulting array stays empty.
sql code:
select `comid`,`comname`,`comlogo` ffd_companies,ffd_comusercon,ffd_users companyid=comid , userid=id , id=1;
code in joomla->customhtmlmodule->sourcerer:
{source} <?php $user = jfactory::getuser(); echo $user->id; $db = jfactory::getdbo(); $query = $db->getquery(true); $query->select($db->quotename(array('comid','comname'))); $query->from($db->quotename(array('ffd_companies','ffd_comusercon','ffd_users'))); $query->where($db->quotename('companyid').' = '.$db->quotename('comid').' , '.$db->quote('userid') .' = '. $db->quote('id').' , '. $db->quote('userid') .' = '.$db->quote($user->id)); $db->setquery($query); $row = $db->loadrowlist(); print_r($row); ?> {/source}
tables & relations :
sql query: select * ffd_users
; id ... standar joomla users table nothing changed
sql query: select * ffd_comusercon
; (index table many many rel. between. users , companies) companyid (foreign key of comid ) userid (foreign key of id )
sql query: select * ffd_companies
; comid comname comtype comlogo comyedek1 comyedek2 omyedek3 comyedek4 comyedek5 comyedek6 comyedek7 comyedek8
this should work:
<?php $user = jfactory::getuser(); echo $user->id; $db = jfactory::getdbo(); $query = $db->getquery(true); $query->select($db->quotename(array('comid','comname'))) ->from($db->quotename(array('ffd_companies','ffd_comusercon','ffd_users'))) ->where($db->quotename('companyid').' = '.$db->quotename('comid')) ->where($db->quote('userid') .' = '. $db->quote('id')) ->where($db->quote('userid') .' = '.$db->quote($user->id)); $db->setquery($query); $row = $db->loadobjectlist(); var_dump($row); ?>
update query (with left joins), it's guess without database structure, guess point
$query->select('comp.id comid, comp.name comname')-> from($db->quotename('#__companies') . ' comp')-> join('left', $db->quotename('#__comusercon') . ' compx on comp.id = compx.company_id')-> join('left', $db->quotename('#__users') . ' usr on usr.id = compx.user_id')-> where('usr.id = ' . $db->quote($user->id))-> group('comp.id');
Comments
Post a Comment