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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.