当前位置: 首页>>代码示例>>PHP>>正文


PHP QueryBuilder::limit方法代码示例

本文整理汇总了PHP中QueryBuilder::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::limit方法的具体用法?PHP QueryBuilder::limit怎么用?PHP QueryBuilder::limit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder::limit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getClosestNode

 /**
  * Get closest node by latitude and longitude
  * This function use fast, but not exact algorithm
  * 
  * @param float $latitude
  * @param float $longitude
  * @param int $type_id
  * @param int $cacheMinutes
  */
 public function getClosestNode($latitude, $longitude, $type_id = null, $cacheMinutes = null)
 {
     if (empty($latitude) or empty($longitude)) {
         return false;
     }
     $qb = new QueryBuilder();
     $qb->select(new Field('*'))->from(Tbl::get('TBL_TREE'))->where($qb->expr()->equal(new Field('lat'), $latitude))->andWhere($qb->expr()->equal(new Field('lng'), $longitude));
     if ($type_id !== null) {
         $qb->andWhere($qb->expr()->equal(new Field('type_id'), $type_id));
     }
     $qb->limit(1);
     $this->query->exec($qb->getSQL(), $cacheMinutes);
     if ($this->query->countRecords()) {
         return $this->query->fetchRecord();
     }
     // If above query doesn't return record, find in some range of posible latitude and longitude
     // As $latitude, $longitude are decimal(8,4)  find with 3 digits to the right of the decimal point
     $digits_after = 3;
     while ($digits_after > -2) {
         //2 digits to the left of the decimal point
         $pow = pow(10, $digits_after);
         $lat_min = $latitude - 1 / 2 / $pow;
         $lat_max = $latitude + 1 / 2 / $pow;
         $lng_min = $longitude - 1 / 2 / $pow;
         $lng_max = $longitude + 1 / 2 / $pow;
         $qb = new QueryBuilder();
         $qb->select(new Field('*'))->from(Tbl::get('TBL_TREE'))->where($qb->expr()->between(new Field('lat'), $lat_min, $lat_max))->andWhere($qb->expr()->between(new Field('lng'), $lng_min, $lng_max));
         $this->query->exec($qb->getSQL());
         if ($this->query->countRecords()) {
             return $this->query->fetchRecord();
         }
         $digits_after--;
         //decrease accuracy
     }
     //////////////////////////////////////////////////////
     // Appear here only if there is no such record		//
     // in wgps_tree table with zero precision/accuracy.	//
     //////////////////////////////////////////////////////
     return null;
 }
开发者ID:Welvin,项目名称:stingle,代码行数:49,代码来源:Gps.class.php

示例2: testLimit2

 /**
  * Generated from @assert limit(10, 1)->text() [==] " LIMIT 1,10".
  *
  * @covers Kotchasan\Database\QueryBuilder::limit
  */
 public function testLimit2()
 {
     $this->assertEquals(" LIMIT 1,10", $this->object->limit(10, 1)->text());
 }
开发者ID:goragod,项目名称:kotchasan,代码行数:9,代码来源:QueryBuilderTest.php

示例3: array

} else {
    $total_results = $peregrine->session->getInt('last_query_total_results');
}
// Order by
if (defined('DEFAULT_ORDER_BY') && DEFAULT_ORDER_BY != '') {
    $qb->order(DEFAULT_ORDER_BY);
}
$per_page = $peregrine->post->getInt('per_page');
// Try to ensure it's somewhat sensible
if ($per_page <= 0 || $per_page > 10000) {
    $per_page = 25;
}
$response = array('results' => false, 'total_results' => $total_results, 'per_page' => $per_page, 'pages' => $total_results > 0 ? ceil($total_results / $per_page) : 0, 'curr_page' => $peregrine->post->getInt('curr_page'), 'sql_hash' => $sql_hash, 'session_hash' => $peregrine->session->getAlnum('sql_conditions_hash'));
// Limit
$offset = ($response['curr_page'] - 1) * $response['per_page'];
$qb->limit($offset, $response['per_page']);
// Merge sql
$sql = $qb->getQuery();
if (defined('WEB_UI_DEBUG') && WEB_UI_DEBUG) {
    print $sql;
    exit;
}
$date_format = 'Y-m-d H:i:s';
if (defined('DEFAULT_DATE_FORMAT') && DEFAULT_DATE_FORMAT) {
    $date_format = DEFAULT_DATE_FORMAT;
}
$statement = $db->query($sql);
$statement->setFetchMode(PDO::FETCH_ASSOC);
if ($statement->rowCount()) {
    $results = array();
    $blocks = $prism->getItemList();
开发者ID:Quartzcraft,项目名称:Website,代码行数:31,代码来源:query.php


注:本文中的QueryBuilder::limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。