Jump to content

Help with multiple queries on same table in Joomla 3


doc1355

Recommended Posts

I'm a newbie in php and writing a php page to be used in Joomla. 
I need to have three different queries: two queries on the same table with different WHERE clause and third query on a second table. Here is my code:

<?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);
?>

Unfortunately, when I test the result with print_r for each $row_, they are all the same and are the result of last query. 
I'm not sure how to fix this problem. Thanks. 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.