• 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);
    

  • 相关阅读:
    CSS3 学习+实践(一)
    调试代码过程中遇到的问题
    python语法学习之函数,类,模块
    CSS3 学习+实践(二)
    网页打印A4纸表格在跨页时自动换页打印的实现
    python语法学习面向对象之继承
    CSS3 学习+实践(三)
    Python语法学习之文件操作
    Freeradius服务器的搭建流程
    当Log4net无法工作时启用trace(How to debug log4net while its not woking)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350875.html
Copyright © 2020-2023  润新知