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

  • 相关阅读:
    11. 盛最多水的容器
    820. 单词的压缩编码
    72. 编辑距离
    10041-回文数
    第六章-希尔排序和堆排序
    第六章-快速排序、合并排序
    第六章 排序-冒泡,选择,插入排序
    第四章-二叉树的运用-AVL平衡二叉树
    第四章-二叉树的运用-排序二叉树的代码
    第四章-二叉树的代码 、二叉树前序中序后序遍历、及运用
  • 原文地址:https://www.cnblogs.com/zhaoyangjian724/p/6200195.html
Copyright © 2020-2023  润新知