PHP Background Pass Value

Source: Internet
Author: User

Foreground data back station value, often is the novice most headache, recently in the study thinkphp time, also encountered this kind of problem, summarizes, go to insufficient place please everybody to advise.

First, the front-page interface code, back to the value of two ways, one is get, the other is post, beginners, no matter what the way it is, the value of success in the next station can be.

First, write a from form,

<form Action= "{: U (Recom/goodsprice)}" method= "post" >

<a href= "{: U (' Recom/goodsprice ', array(' price ' =' + ')}" > Prices greater than 700</a>// In this case, let's introduce the value of hyperlinks.

</form>

This price is passed to the backstage, after passing, but also to accept the value to pass, see step Two,

Second, the background of the control layer code is as follows:

Public Function Goodsprice () {
$price = I (' price ');//This will get the value of the price of the foreground pass.
Print_r ("Price:". $price. " ");//Check the success of the pass value, need to run after the source code to open the foreground whether there is this value
$model = D (' Goods ');//Select a table in the database, for example, call Goods watch.
$res = $model->selectprice ($price);//key moment, call the Selectprice function of the model layer, take $price this parameter to pass

$this->assign (' res ', $res ["date"]);//Get data, named Res
$this->assign (' page ', $res ["page"]), a paging method that comes with//thinkphp, is simple, but needs to be configured in the model layer and explained below.

$this->display ();//This is the display interface
}

Third, the code of the model layer is as follows:

Public Function Selectprice ($price) {
$this->db (1, "DB_CONFIG1")->db (1);//Select Database

$map [' price '] = Array (' GT ', $price); Defining query criteria

$count = $this->db (1, "DB_CONFIG1")->where ($map)->count ();//statistic Bar number
$page = new \think\page ($count, 10);//pagination processing
$show = $page->show ();
$limit = $page->show ();
$limit = $page->firstrow. ",". $page->listrows;

$goodsprice = $this->db (1, "DB_CONFIG1")->limit ($limit)->where ($map)->select ();//sql statement
Print_r ($this->getlastsql ());//debug dedicated, output last SQL statement
$res ["date"] = $goodsprice;
$res ["page"] = $show;

return $res;
}

The specific code and procedure is so simple, do you have any help?

PHP Background Pass Value

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.