Thanks, Bruce.
Well, they're interdependent in a chain kind of way, rather than a "all share one field" kind of way.
By that I mean that
jos_users has $id which links to $user_id in jos_jusers_extended_data
jos_jusers_extended_data has $fvalue which links to $surveyls_title in lime_surveys_languagesettings
lime_surveys_languagesettings has $surveyls_survey_id which is the value of x in the table name lime_tokens_x
lime_tokens_x has $completed and $token and I need to know if there's a row where $completed = "Y" and $token = $user->username
So, what I'm starting with is that I know $user->username and $user->id by using
From knowing the $user->username and $user->id, I need to go to the jos_jusers_extended_data to find out which project they've signed up for ($fvalue when $field_id=1), then go to the lime_surveys_languagesettings to find out the id numbers of all the surveys that are associated with that project ($surveyls_title = $fvalue), then go to the appropriate lime_tokens_x tables to find out if there are any $completed = "Y"
As I wrote that out, I realized that since there could be multiple lime_tokens_x tables applicable to a particular user, I probably have to have a separate SELECT statement for each one. And as I think about that, I think it might be just as easy to query all lime_tokens_x tables looking for $token = $user->username and $completed = "Y" rather than trying to figure out which token tables to check (so, for example, instead of going through a long process to figure out which 3 or 4 of 12 surveys a user is taking in order to only check those 3 or 4 tables, just check all 12).
This would work because at registration to the Joomla site, I've added code to put the username in the $token field of the appropriate lime_tokens_x tables.
So, now my needs change somewhat - to focus on generating the list of surveys someone is taking and whether they're done - so, I think I need something like this:
Code: Select all
$db = JFactory::getDBO();
$user = &JFactory::getUser();
$sql= "SELECT `completed` FROM `lime_tokens_14114` WHERE `token` = $user->username";
$db->setQuery($sql);
$db->query();
if($db->getNumRows != 0) {
$sql = "SELECT `surveyls_title` FROM `lime_surveys_languagesetting` WHERE `sid` = '14114'";
$db->setQuery($sql);
$db->query();
if($completed == 'Y') {
echo $surveyls_title. " - Completed";
} elseif ($completed == 'N') {
echo "<a href="path/to/survey/">".$surveyls_title."</a> - Not Completed";
}
}
And I would have to do this for
all surveys that are currently active - which seems more straightforward than where I started with trying to narrow down how many queries I
had to do based on that fvalue.
So, does what I've got there look okay? Is there a better (more efficient) way to achieve it?
Thanks.