找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 406|回復: 0

資料表不重複修改 distinct

[複製鏈接]

257

主題

38

回帖

1138

積分

管理員

積分
1138
發表於 2023-5-25 11:03:16 | 顯示全部樓層 |閱讀模式

1)Editor.PHP 
來自:

1
2
3
4
public function pkey ( $_=null )
    {
        return $this->_getSet( $this->_pkey, $_ );
    }

至:

1
2
3
4
6
7
8
9
public function pkey ( $_=null )
    {
        return $this->_getSet( $this->_pkey, $_ );
    }
 
    public function distinct ($_=null)
    {
        return $this->_getSet( $this->_distinct, $_ );
    }

在我改變的同一個文件中:
來自:

1
2
3
4
6
7
private function _get( $id=null, $http=null )
    {
         
        $query = $this->_db
            ->query("select")
            ->table( $this->_table )
            ->get( $this->_pkey );

至:

1
2
3
4
6
7
8
9
10
private function _get( $id=null, $http=null )
{
     
    $query = $this->_db
        ->query("select")
        ->table( $this->_table )
        ->get( $this->_pkey );
     
    if ($this->distinct())
         $query->distinct(true);

為了使rowcount正確,我在下一個地方添加了相同的不同條件:

1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Get the number of rows in the result set
$ssp_set_count = $this->_db
    ->query('select')
    ->table( $this->_table )
    ->get( 'COUNT('.$this->_pkey.') as cnt' );
if ($this->distinct())
     $query->distinct(true);
$this->_get_where( $ssp_set_count );
$this->_ssp_filter( $ssp_set_count, $http );
$this->_perform_left_join( $ssp_set_count );
$ssp_set_count = $ssp_set_count->exec()->fetch();
 
// Get the number of rows in the full set
$ssp_full_count = $this->_db
    ->query('select')
    ->table( $this->_table )
    ->get( 'COUNT('.$this->_pkey.') as cnt' );
if ($this->distinct())
     $query->distinct(true);

完成所有這些後,我使用了我的編輯器實例,如下所示:

1
2
3
4
6
7
8
9
10
$editor=Editor::inst( $db, 'jobs' )
    ->fields(
        Field::inst( 'company.Name' ),
        Field::inst( 'stores.short_add' )->validator( 'Validate::notEmpty' ),
                ......
                )
        ->LeftJoin(......);
$editor->distinct(true); //Only add this line if you want distinct values!
$editor->where(.....);
$editor->on(.....);


您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|DoIT 科技論壇

GMT+8, 2025-6-16 04:53 , Processed in 0.022126 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表