Home Backend Development PHP Tutorial Analysis on ThinkPHP's use of getlist method to implement data search function

Analysis on ThinkPHP's use of getlist method to implement data search function

Jun 08, 2018 am 11:58 AM
thinkphp Search function data

This article mainly introduces ThinkPHP's use of the getlist method to implement data search functions. It analyzes in detail in the form of examples, thinkPHP's implementation of reading and displaying data based on given conditions based on getlist and other related operating techniques. Friends who need it can Refer to the following

The example of this article describes ThinkPHP's use of the getlist method to implement the data search function. Share it with everyone for your reference, the details are as follows:

I write the getlist method in the model in ThinkPHP. In fact, the so-called search function is nothing more than like %string%, or other used in database queries. The field name = specific value, these sql statements are spliced ​​into the and statement;

In HTML:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

<form action="" method="get">

    <table class="account_table" width="100%" cellpadding="0" cellspacing="0">

      <tr>

        <td style="text-align:right">订单号:</td>

        <td>

          <input id="Orderid" name="order_sn" class="inp_wid3" type="text" value="{$_GET[&#39;order_sn&#39;]}"/>

        </td>

        <td style="text-align:right">

          下单日期:

        </td>

        <td colspan="5">

          <input type="text" class="inp_wid2" id="BeginTime" name="begintime" value="{$_GET[&#39;begintime&#39;]}" />

          

          <input type="text" class="inp_wid2" id="EndTime" name="endtime" value="{$_GET[&#39;endtime&#39;]}" />

           交易完成日期

          <input type="text" class="inp_wid2" id="txtFinishedBeginTime" name="finishbegintime" value="{$_GET[&#39;finishbegintime&#39;]}" />

          

          <input type="text" class="inp_wid2" id="txtFinishedEndTime" name="finishendtime" value="{$_GET[&#39;finishendtime&#39;]}" />

           订单金额:

          <input type="text" class="inp_wid2" id="txtMoneyMin" name="count_price_min" value="{$_GET[&#39;count_price_min&#39;]}"/>

          

          <input type="text" class="inp_wid2" id="txtMoneyMax" name="count_price_max" value="{$_GET[&#39;count_price_max&#39;]}" />

        </td>

      </tr>

      <tr>

        <td style="text-align:right; width:80px">采购商名称:</td>

        <td style="width:140px">

          <input id="SupermarketName" name="user_nick_name" class="inp_wid3" type="text" value="{$_GET[&#39;user_nick_name&#39;]}" />

        </td>

        <td style="text-align:right; width:80px">采购商账号:</td>

        <td style="width:140px">

          <input id="SupermarketZh" name="user_name" class="inp_wid3" type="text" value="{$_GET[&#39;user_name&#39;]}" />

        </td>

      </tr>

      <tr>

        <td colspan="2">

          <input class="search_btn1" type="submit" value="搜索" id="Search" />

          </td>

      </tr>

    </table>

</form>

Copy after login

I see no GET Method to submit the form, this is the query condition filling option;

In the controller:

1

2

$order_msg=$order->getList();

$this->assign(&#39;info&#39;,$order_msg);//这个获取订单的详细信息

Copy after login

In the Model:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

public function getList($pagesize=25){

     $tableName = $this->getTableName();

   $where = $tableName.&#39;.service_id = &#39;.$_SESSION[&#39;service_site&#39;][&#39;service_id&#39;];

   if(!empty($_GET[&#39;order_sn&#39;])){//查询订单号

       $where.= " and $tableName.`order_sn` like &#39;%".$_GET[&#39;order_sn&#39;]."%&#39;";

     }

   if(!empty($_GET[&#39;count_price_min&#39;])){//查询订单最小金额

       $where.= " and $tableName.count_price >=".$_GET[&#39;count_price_min&#39;]."";

     }

   if(!empty($_GET[&#39;begintime&#39;])){//下单开始日期搜索

    $_GET[&#39;begintime&#39;]=strtotime($_GET[&#39;begintime&#39;]);//将日期转为时间戳

    $where.= " and $tableName.add_time >=".$_GET[&#39;begintime&#39;]."";

    $_GET[&#39;begintime&#39;]=date(&#39;Y-m-d&#39;,$_GET[&#39;begintime&#39;]);//将日期转为时间戳

   }

   if(!empty($_GET[&#39;endtime&#39;])){//下单结束日期搜索

     $_GET[&#39;endtime&#39;]=strtotime($_GET[&#39;endtime&#39;]);//将日期转为时间戳

    $where.= " and $tableName.add_time <=".$_GET[&#39;endtime&#39;]."";

    $_GET[&#39;endtime&#39;]=date(&#39;Y-m-d&#39;,$_GET[&#39;endtime&#39;]);//将时间戳转换成日期,方便刷新页面后前台显示

   }

   if(!empty($_GET[&#39;finishbegintime&#39;])){//交易完成开始日期搜索

    $_GET[&#39;finishbegintime&#39;]=strtotime($_GET[&#39;finishbegintime&#39;]);//将日期转为时间戳

    $where.= " and $tableName.ok_time >=".$_GET[&#39;finishbegintime&#39;]."";

    $_GET[&#39;finishbegintime&#39;]=date(&#39;Y-m-d&#39;,$_GET[&#39;finishbegintime&#39;]);//将日期转为时间戳

   }

   if(!empty($_GET[&#39;finishendtime&#39;])){//交易完成结束日期搜索

     $_GET[&#39;finishendtime&#39;]=strtotime($_GET[&#39;finishendtime&#39;]);//将日期转为时间戳

    $where.= " and $tableName.ok_time <=".$_GET[&#39;finishendtime&#39;]."";

    $_GET[&#39;finishendtime&#39;]=date(&#39;Y-m-d&#39;,$_GET[&#39;finishendtime&#39;]);//将时间戳转换成日期,方便刷新页面后前台显示

   }

   if(!empty($_GET[&#39;send&#39;])){//查询已发货预警订单,发货时间距离此刻超过五天

    $where.= " and $tableName.send_time < &#39;".(time()-60*60*24*5)."&#39;";

   }

   if(!empty($_GET[&#39;doingorder&#39;])){//查询处理中的订单

    $where.= " and $tableName.status in (0,1)";

   }

   if(!empty($_GET[&#39;warningorder&#39;])){//查询预警的订单:已经付款且时间超过24小时未发货

    $where.= " and $tableName.pay_time < &#39;".(time()-60*60*24)."&#39;";

   }

   if(!empty($_GET[&#39;warningorder&#39;])){//查询预警的订单:已经付款且时间超过24小时未发货

    $where.= " and $tableName.is_pay = 1 ";

   }

   if(!empty($_GET[&#39;warningorder&#39;])){//查询预警的订单:已经付款且时间超过24小时未发货

   $where.= " and $tableName.status in (0,1)";

   }

   if(!empty($_GET[&#39;count_price_max&#39;])){//查询订单最大金额

    $where.= " and $tableName.count_price <=".$_GET[&#39;count_price_max&#39;]."";

   }

   if(!empty($_GET[&#39;user_nick_name&#39;])){//查询采购商名称

    $where.= " and fab_user.nick_name like &#39;".$_GET[&#39;user_nick_name&#39;]."%&#39;";

   }

   if(!empty($_GET[&#39;user_name&#39;])){//查询采购商账号

    $where.= " and fab_user.user_name like &#39;".$_GET[&#39;user_name&#39;]."%&#39;";

   }

   if(!empty($_GET[&#39;supplier_nick_name&#39;])){//查询供应商商名称

    $where.= " and fab_supplier.nick_name like &#39;".$_GET[&#39;supplier_nick_name&#39;]."%&#39;";

   }

   if(!empty($_GET[&#39;supplier_name&#39;])){//查询供应商账号

    $where.= " and fab_supplier.supplier_name like &#39;".$_GET[&#39;supplier_name&#39;]."%&#39;";

   }

   if($_GET[&#39;history&#39;] == 1){

     $where .= " and {$tableName}.status in (2,3,4) ";

   }

   if(($_GET[&#39;pay_type&#39;])!=""&&($_GET[&#39;pay_type&#39;])!=-1){//查询支付方式

    $where.= " and fab_order_info.pay_type = ".$_GET[&#39;pay_type&#39;]."";

   }

   if(($_GET[&#39;status&#39;])!=""&&($_GET[&#39;status&#39;])!=-1){//查询订单状态

    $where.= " and fab_order_info.status = ".$_GET[&#39;status&#39;]."";

   }

     if(!empty($_GET[&#39;stime&#39;]) && !empty($_GET[&#39;etime&#39;])){

       $stime = strtotime($_GET[&#39;stime&#39;]);

       $etime = strtotime($_GET[&#39;etime&#39;]) + 24*60*60;

       $where.= " and ($tableName.`inputtime` between &#39;$stime&#39; and &#39;$etime&#39;)";

     }

     $count = $this->where($where)->count();

     $this->countNum = $count;

     $Page = new \Think\Page($count,$pagesize);

     $this->page = $Page->show();

     $limit = $Page->firstRow.&#39;,&#39;.$Page->listRows;

    $sql="select $tableName.*,fab_supplier.nick_name as supplier_nick_name,fab_user.nick_name as user_nick_name

    from ($tableName left join fab_supplier on fab_order_info.supplier_id=fab_supplier.supplier_id)

    left join fab_user on fab_order_info.user_id=fab_user.user_id where $where order by $tableName.`order_id` desc limit $limit";

    $sqls="select sum(fab_order_info.count_price) as order_price,count(fab_order_info.count_price) as order_count

    from $tableName where $where order by $tableName.`order_id` desc limit $limit";

    $this->sql_msg=$this->query($sqls);

    return $this->query($sql);//订单详细信息

}

Copy after login

You only need to pay attention to the GET data acquisition, and then splice the SQL statement; why do you always splice incorrectly! ! !

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<?php

namespace Admin\Model;

use Think\Model;

class KuaidicompanyModel extends Model {

  private $page = "";

  public function getList($pagesize=25){

    $where = &#39;1&#39;;

    $tableName = $this->getTableName();

    $count = $this->where($where)->count();

    $Page = new \Think\Page($count,$pagesize);

    $this->page = $Page->show();

    $limit = $Page->firstRow.&#39;,&#39;.$Page->listRows;

    return $this->query("select * from $tableName where $where order by $tableName.`id` asc limit $limit ");

  }

  public function getPage(){

    return $this->page;

  }

}

Copy after login
Copy after login

Simplified general version of getlist, suitable for paging.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<?php

namespace Admin\Model;

use Think\Model;

class KuaidicompanyModel extends Model {

  private $page = "";

  public function getList($pagesize=25){

    $where = &#39;1&#39;;

    $tableName = $this->getTableName();

    $count = $this->where($where)->count();

    $Page = new \Think\Page($count,$pagesize);

    $this->page = $Page->show();

    $limit = $Page->firstRow.&#39;,&#39;.$Page->listRows;

    return $this->query("select * from $tableName where $where order by $tableName.`id` asc limit $limit ");

  }

  public function getPage(){

    return $this->page;

  }

}

Copy after login
Copy after login

The streamlined version of MODEL is used for automatic data verification

The above is the entire article Content, I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Analysis on ThinkPHP watermarking and setting watermark position

About thinkphp framework to implement data addition and Displayed functional methods

Source code analysis of setInc method in thinkphp3.2.0

The above is the detailed content of Analysis on ThinkPHP's use of getlist method to implement data search function. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1225
24
Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

DDREASE is a tool for recovering data from file or block devices such as hard drives, SSDs, RAM disks, CDs, DVDs and USB storage devices. It copies data from one block device to another, leaving corrupted data blocks behind and moving only good data blocks. ddreasue is a powerful recovery tool that is fully automated as it does not require any interference during recovery operations. Additionally, thanks to the ddasue map file, it can be stopped and resumed at any time. Other key features of DDREASE are as follows: It does not overwrite recovered data but fills the gaps in case of iterative recovery. However, it can be truncated if the tool is instructed to do so explicitly. Recover data from multiple files or blocks to a single

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Alibaba 7B multi-modal document understanding large model wins new SOTA Alibaba 7B multi-modal document understanding large model wins new SOTA Apr 02, 2024 am 11:31 AM

New SOTA for multimodal document understanding capabilities! Alibaba's mPLUG team released the latest open source work mPLUG-DocOwl1.5, which proposed a series of solutions to address the four major challenges of high-resolution image text recognition, general document structure understanding, instruction following, and introduction of external knowledge. Without further ado, let’s look at the effects first. One-click recognition and conversion of charts with complex structures into Markdown format: Charts of different styles are available: More detailed text recognition and positioning can also be easily handled: Detailed explanations of document understanding can also be given: You know, "Document Understanding" is currently An important scenario for the implementation of large language models. There are many products on the market to assist document reading. Some of them mainly use OCR systems for text recognition and cooperate with LLM for text processing.

See all articles