doc1355 Posted October 24, 2018 Share Posted October 24, 2018 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. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 24, 2018 Share Posted October 24, 2018 Can you think of any other way that you might possibly be able to get the results of three different queries besides trying to run them all at the same time? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.