简体   繁体   中英

Joomla JDatabase to “test” state of an item in an array

I have made a query as follows:

    $user = JFactory::getUser();
$uid = $user->id;
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "SELECT a.id, a.menu_item_id, a.req_form FROM `team_form_lists` AS a LEFT JOIN #__comprofiler AS f ON f.cb_teamid = a.team_number WHERE f.user_id = $uid";
$db->setQuery($query);
$forms = $db->loadObjectList('id');
return $forms;

And it returns:

    Array ( 
[3] => stdClass Object ( [id] => 3 [menu_item_id] => 1378 [req_form] => 334 Basic Information Form ) 
[4] => stdClass Object ( [id] => 4 [menu_item_id] => 1379 [req_form] => 334 Extra Curricular Activity Consent and Release ) 
[5] => stdClass Object ( [id] => 5 [menu_item_id] => 1377 [req_form] => 334 Florida FHSAA Concussion ) 
[7] => stdClass Object ( [id] => 7 [menu_item_id] => 1380 [req_form] => 334 Emergency Treatment Authorization and Health Emergency Information ) 
[8] => stdClass Object ( [id] => 8 [menu_item_id] => 1381 [req_form] => 334 Random Drug and Alcohol Testing ) 
)

Which is precisely what I need to generate a dynamic "menu" to allow the user to navigate to the appropriate form with a link.

Problem is, I want to "test" the forms against another db table to see which ones have already been filled out. I have tried a query like this:

    foreach ($forms as $form){ 
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query = "SELECT COUNT( `id` ) FROM `#__facileforms_records` WHERE `title` = '$form->req_form' AND `user_id` = $uid ";
$db->setQuery($query);
$state = $db->loadResult();
return $state;
}

problem is, 2nd query returns the same array. I know this comes down to ignorance on my part, just looking for a nudge in the right direction, Thanks.

THe fact that it is returning an array is the give away. YOU still have $query with the first query. YOu need to either make that $query2 or do $query->clear();. Then you'll start with a clean slate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM