PHP user query and judgment

墨辰丷
Release: 2023-03-31 11:32:02
Original
2479 people have browsed it

This article mainly introduces PHP for user query and judgment. Interested friends can refer to it. I hope it will be helpful to everyone.

The example of this article describes the user query class implemented in PHP. The specific implementation method is as follows:

<?php
 class user
 {
  var $usertable;
  function get_oneuser($field,$value)
  {
   $field_array=array("id","name");  //查询方式
   if(in_array($field,$field_array))
   {
    $sql="SELECT * FROM `$this->usertable` WHERE $field=&#39;$value&#39;";
    $db=new database;
    $res=$db->execute($sql);
    $obj_user=mysql_fetch_object($res);
    return $obj_user;
   }
   else echo "查询方式不对";
  }
  function get_moreusers()
  {
   global $db;
   $argnums=func_num_args();
   $argarr=func_get_args();
   switch($argnums)
   {
    case 0:
     $sql="SELECT * FROM `$this->usertable`";
     break;
    case 2:
     $sql="SELECT * FROM `$this->usertable` WHERE $argarr[0]=&#39;$argarr[1]&#39;";
     break;
    case 4:
     $sql="SELECT * FROM `$this->usertable` WHERE $argarr[0]=&#39;$argarr[1]&#39; AND $argarr[2]=&#39;$argarr[3]&#39;";
     break;
   }
   //$db=new database;
   $res=$this->execute($sql);
   $obj_arr=array();
   while($obj=mysql_fetch_object($res))
   {
    $obj_arr[]=$obj;
   }
   return $obj_arr;
  }
 }
?>
Copy after login

Summary: The above is the entire content of this article. I hope it can be useful for everyone’s learning. helped.

Related recommendations:

php method for recursive operations on files

php combined with session Methods of operating database

PHP method of accepting files and getting suffix names

The above is the detailed content of PHP user query and judgment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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!