2

次のテーブルがあります。

tbl_users
===============
uid
username
password
gid

tbl_groups
===============
gid
name
type

f3 で sqlmapper を使用して、ユーザー名が $_POST["username"] に等しい両方のテーブルをクエリし、グループ名とタイプも取得できるようにする方法を見つけようとしています。このフレームワークを sqlmapper で使用して、同様のクエリを結合することは可能ですか?

私は周りを検索してきましたが、その例は見つかりません。

4

2 に答える 2

2

{VIEW} を使用した例を次に示します。

Viewを使用してSQL Mapperでページネーションを実装しましたview_user_list_with_referral

    $dropInstantWinnerView = $this->db->exec("DROP VIEW IF EXISTS view_user_list_with_referral;");
    $createInstantWinnerView = $this->db->exec("CREATE VIEW view_user_list_with_referral AS SELECT u.fb_id, fb_link, name, r.referred_by, u.created FROM users u LEFT OUTER JOIN referral r ON u.fb_id=r.joinee ");
    $user = new \DB\SQL\Mapper($this->db,'view_user_list_with_referral');
    $limit = 20;
    $page = Pagination::findCurrentPage();
    $order_condition = F3::get("PARAMS.order_condition");
    $order_class= "";
    if(!empty($order_condition)){
        $cond = explode(":", $order_condition);
        $option = array('order' => $cond[0].' '.$cond[1]);
        if($cond[1]=='ASC'){
            $order_condition = $cond[0].':DESC';
            $order_class = ":DESC";
        }else{
            $order_condition = $cond[0].':ASC';
            $order_class = ":ASC";
        }
    }else{
        $option = array('order' => 'created DESC');
    }

    $subset = $user->paginate($page-1, $limit, null, $option);

    $pages = new Pagination($subset['total'], $limit);
    $pages->setTemplate("admin/pagebrowser.html");

    F3::set('pagebrowser', $pages->serve());
    //echo "<pre>";print_r($subset);exit;
    F3::set('page', $page);
    F3::set('order_condition', $order_condition);
    F3::set('total_found_records', $user->count());

誰かの時間を節約できることを願っています:)

于 2014-08-29T11:45:18.360 に答える