Php 如何使用flourishlib'与预览和保存交互;s fRecordSet';什么是构建方法?
假设我有一个名为Php 如何使用flourishlib'与预览和保存交互;s fRecordSet';什么是构建方法?,php,mysql,flourishlib,Php,Mysql,Flourishlib,假设我有一个名为local\u ads的数据库表 现在,创建本地广告时,必须能够查看其预览,如果他满意,则保存它。此外,如果一个人想要更新本地广告,那么他可能希望在覆盖实况版本的记录之前查看其预览 因此,我有一个外键用于local\u ads表,名为parent\u id。如果这是空的,那么它是一个预览(至少根据我最初的想法)。否则它是活的。保存预览时,有两种情况: 案例1:尚未链接到预览的实时记录。在这种情况下,将一条新记录插入到local\u ads表中,其中父\u id指向预览 案例2:有
local\u ads
的数据库表
现在,创建本地广告时,必须能够查看其预览,如果他满意,则保存它。此外,如果一个人想要更新本地广告,那么他可能希望在覆盖实况版本的记录之前查看其预览
因此,我有一个外键用于local\u ads
表,名为parent\u id
。如果这是空的,那么它是一个预览(至少根据我最初的想法)。否则它是活的。保存预览时,有两种情况:
案例1:尚未链接到预览的实时记录。在这种情况下,将一条新记录插入到local\u ads
表中,其中父\u id
指向预览
案例2:有一条实时记录链接到预览。在这种情况下,将更新实时记录
一切看起来都很好,但我在网格中显示结果时遇到了一个问题。如果不存在实时版本的记录,我想显示预览,如果存在,则只显示实时版本。我想展示一些关于
select col1, col2, col3, col4
from local_ads glob
where (not (parent_id is null))
or ((select id from local_ads temp where temp.parent_id = glob.id limit 0, 1) is null)
但是我有几个问题。我们有一个逻辑或
(我想知道如何使用fluishlib的fRecordSet
的build
方法在逻辑操作数之间使用逻辑或
)。另外,这个查询是二维的,速度很慢。此外,我想知道如何执行子查询。此外,我不知道如何使用is
运算符,因为在is null
中
因此,我不得不重新思考我的想法,并得出以下结论:
select col1, col2, col3, col4
from local_ads
where parent_id < id or parent_id >= id
这是:
* 'column>=:' => 'other_column' // column >= other_column
所以我知道如何将这些添加到过滤器中,但我应该如何“或”它们
到目前为止,我已经这样尝试过:
public static function localAd() {
$User = Globe::load('CurrentUser');
$Smarty = Globe::load('Smarty');
//handle default options
$options = array(
'recordsPerPage' => 20,
'pageLinks' => 10,
);
$page = 0;
if (isset($_GET['p'])) {
$page = $_GET['p'];
}
//get the data
$startIndex = (isset($page)) ? $page * $options['recordsPerPage'] : 0;
$filters = array();
if ($User->getType() == 'local_admin') {
$filters['domain='] = $User->getDomain();
}
$records = fRecordSet::build('LocalAd', $filters, array('created' => 'desc'), $options['recordsPerPage'], $page + 1);
//create result object for pagination
$Result = array(
"recordsReturned" => $records->count(),
"totalRecords" => $records->count(true),
"startIndex" => intval($startIndex),
"records" => $records->export(),
'recordsPerPage' => $options['recordsPerPage'],
'pageLinks' => $options['pageLinks'],
'currentPage' => $page,
//'options' => $options
);
$Result['totalPages'] = ceil($Result['totalRecords'] / $Result['recordsPerPage']);
$Smarty->assign('Result', $Result);
$Smarty->assign('ManagerURL', '?a=localAd');
AdminView::display('Admin/LocalAd/main.tpl');
}
请注意,在某些情况下,我还必须检查域。与此同时,我已经设法解决了这个问题。这就是我们如何定义过滤器集来解决问题中提到的问题:
$filters = array();
if ($User->getType() == 'local_admin') {
$filters['domain='] = $User->getDomain();
}
$filters['parent_id<:|parent_id>=:'] = array('id', 'id');
$filters=array();
如果($User->getType()=='local\u admin'){
$filters['domain=']=$User->getDomain();
}
$filters['parent_id=:']=数组('id','id');
$filters = array();
if ($User->getType() == 'local_admin') {
$filters['domain='] = $User->getDomain();
}
$filters['parent_id<:|parent_id>=:'] = array('id', 'id');