tp框架怎么根据传的参数查询数据?

WBOY
Release: 2016-06-20 12:25:44
Original
1006 people have browsed it

比如一个搜索表单根据用户输入的值搜索name字段下的对应的名字 这个应该怎么查询呢?我只会写这么一点 tp里面传值不知道该怎么弄 怎么传值怎么接收?
比如这里的这个action值应该写什么?  我看手册只有在后台接收数据的  用的是I函数   接收完了怎么使用呢?

<form method="post">    <input type="text" name="name" />    <button type="submit">Submit</button></form>
Copy after login

后台也不会写 只写了一点
class FirstController extends Controller {    public function qq(){    	$qq=new \Model\qqModel();        $qq->field('name');        $info=$qq->select();    	$this->assign('info',$info);        $this->display();    }}
Copy after login


我问了问别人他们说应该这样改
<form action="{:U('Index/qq')}" method="post">   //不懂这里的action后面的意思 我把里面Index/qq换成first/qq试了一下还是报错    <input type="text" name="name" />    <button type="submit">Submit</button></form>
Copy after login

public function search(){    $name=I("post.name");    $info=M("qq")->where('name like %'.$name.'%')->select();    var_dump($info);}
Copy after login

这样试了一下   提示报错了:1064:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%% )' at line 1 [ SQL语句 ] : SELECT * FROM `qq` WHERE ( name like %% )




回复讨论(解决方案)

fffffffffffffffffffffffffffffffffffffffff

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!