zoukankan      html  css  js  c++  java
  • ThinkPHP 3.1.2 查询方式的一般使用1

    	
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $id=$_GET['id'];
    		$arr=$m->where("id=$id")->getField('username');
    		//var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    
    
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $id=$_GET['id'];
    		//$arr=$m->where("id=$id")->getField('username');
    		$arr=$m->where("id=$id")->find();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $id=$_GET['id'];
    		//$arr=$m->where("id=$id")->getField('username');
    		$arr=$m->where("id=$id")->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $id=$_GET['id'];
    		//$arr=$m->where("id=$id")->getField('username');
    		$arr=$m->where("sex=1 and username='gege'")->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    
    //select
    
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $username=$_GET['username'];
    		//$arr=$m->where("id=$id")->getField('username');
    		$arr=$m->where("sex=1 and username='$username'")->find();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    
    //select 2
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $username=$_GET['username'];
    		
    		$sex=$_GET['sex'];
    		//$arr=$m->where("id=$id")->getField('username');
    		//$arr=$m->where("sex=$sex and username='$username'")->find();
    		
    		$data['sex']=$sex;
    		$data['username']="$username";
    		$arr=$m->where($data)->find();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    
    //select or
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	
    	    $username=$_GET['username'];
    		
    		$sex=$_GET['sex'];
    		//$arr=$m->where("id=$id")->getField('username');
    		//$arr=$m->where("sex=$sex and username='$username'")->find();
    		
    		//默认条件是and
    		$data['sex']=$sex;
    		$data['username']="$username";
    		$data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    //select id>6的
    
    	public function show(){
    		echo "访问了index模块下的show方法!!";
    		echo "欢迎你".$_GET['name'].'你的年龄是'.$_GET['age'];
    		$m=M('user');
    	     $id=$_GET['id'];
    	    // $username=$_GET['username'];
    		
    		// $sex=$_GET['sex'];
    		//$arr=$m->where("id=$id")->getField('username');
    		//$arr=$m->where("sex=$sex and username='$username'")->find();
    		
    		//默认条件是and
    		$data['id']=array('GT',6);
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    //select <=
    
    //默认条件是and
    		$data['id']=array('ELT',$id);
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    
    
    //select like 
    
    	//默认条件是and
    		$data['username']=array('like',"%$username");
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    
    
    //select not like
    
    	$data['username']=array('notlike',"%$username");
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    	}
    
    //select like or
    
    	$data['username']=array('like',array("%$username%","%2%"));
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    
    //select like and
    
    	$data['username']=array('like',array("%$username%","%2%"),'and');
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    
    //select between 方式
    
    	$data['id']=array('between',array($id1,$id2));
    		
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    
    
    //select not between
    
    $data['id']=array('not between',array($id1,$id2));
    		
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    
    //select in 
    
    	$data['id']=array('in ',array($id1,$id2));
    		
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    		$this->display();
    
    
    //select not in
    
    		$data['id']=array('not in ',array($id1,$id2));
    		
    		// $data['sex']=$sex;
    		// $data['username']="$username";
    		// $data['_logic']='or';
    		$arr=$m->where($data)->select();
    		var_dump($arr);
    		$this->assign('data',$arr);
    

  • 相关阅读:
    django-makdown编辑器之编辑和显示
    Jenkins以root用户运行的方法
    利用Django提供的ModelForm增删改数据的方法
    Django之URL反向解析
    腾讯云-tke-设置configmap
    线程同步
    测试人的福利来了!柠檬班题库免费对外开放啦。
    如何设计一个高并发系统?
    为什么使用消息队列?消息队列有什么优点和缺点?Kafka、ActiveMQ、RabbitMQ、RocketMQ 都有什么优点和缺点?
    记一次idea问题—performing vcs refresh...
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200196.html
Copyright © 2011-2022 走看看