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='$value'"; $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]='$argarr[1]'"; break; case 4: $sql="SELECT * FROM `$this->usertable` WHERE $argarr[0]='$argarr[1]' AND $argarr[2]='$argarr[3]'"; break; } //$db=new database; $res=$this->execute($sql); $obj_arr=array(); while($obj=mysql_fetch_object($res)) { $obj_arr[]=$obj; } return $obj_arr; } } ?>
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!