简体   繁体   English

Joomla JDatabase可“测试”数组中项目的状态

[英]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. 您的第一个查询仍然有$ query。 YOu need to either make that $query2 or do $query->clear();. 您需要使$ query2或执行$ query-> clear();。 Then you'll start with a clean slate. 然后,您将从一个干净的开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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