一页上的Joomla多个查询仅返回最后一个查询

时间:2018-10-24 02:13:06

标签: php database mysqli

我正在写一个要在Joomla中使用的php页面,我需要有三个不同的查询:同一表上的两个查询具有不同的WHERE子句,而第二个表上的第三个查询。 这是我的代码:

<?php 
// Cnnect to response database and get the user's data that matches the logged in user
$query_user->select($db_user->quoteName(array('user_ID', 'parent_id', 'mbr_status', 'payment_status')))
               ->from($db_user->quoteName('mb_response'))
               ->where($db_user->quoteName('user_ID') . ' LIKE ' . $db_user->quote($joomla_user_id));


// Cnnect to response database and get the other's data that are related to the logged in user
$query_other->select($db_other->quoteName(array('user_ID', 'parent_id', 'mbr_status', 'payment_status')))
            ->from($db_other->quoteName('mb_response'))
            ->where($db_other->quoteName('user_ID') . ' LIKE ' . $db_other->quote($joomla_user_id));

// Connect to profile database and user's information that matches the logged in user
$query_profile->select($db_profile->quoteName(array('user_ID', 'address', 'phone')))
              ->from($db_profile->quoteName('mb_user_profile'))
              ->where($db_profile->quoteName('user_ID') . ' LIKE ' . $db_profile->quote($joomla_user_id));


// Reset the query using our newly populated query object.
$db_user->setQuery($query_user);
$db_other->setQuery($query_other);
$db_profile->setQuery($query_profile);

// Load the results as a list of stdClass objects<br>
$row_user = $db_user->loadAssoc();
$row_other = $db_other->loadAssoc();
$row_profile = $db_profile->loadAssoc();

// Extract all keys and values for the row and add a PREFIX based on the query. All prefixes ends with _ e.g $user_user_ID 
extract($row_user, EXTR_PREFIX_ALL, "user");
extract($row_other, EXTR_PREFIX_ALL, "other");
extract($row_profile, EXTR_PREFIX_ALL, "profile");

print_r($row_user);
print_r($row_other);
print_r($row_profile);
?>

不幸的是,当我用print_r测试每个$ row_的结果时,它们都是相同的,并且是最后一次查询的结果。

我不确定如何解决此问题。 谢谢。

0 个答案:

没有答案