Thinkphp is a relatively good PHP development framework that can quickly develop an MVC architecture management system. We need to use the select() and find() methods. Both methods can return data set arrays, but what is the difference? Take a look at my code comparison first:
$tech=M('techlevel','HR_CS_','DB_CONFIG2');
$Data=$tech->where('id=1')->find ();
dump($Data);
$Data=$tech->where('id=1')->select();
dump($Data);
result
array (6){
["ID"]=>int(1)
["TechLevel"]=>string(2)"10"
["Remark"]=>string(4)" ��"
["CreateDate"]=>string(19)"2013-03-1415:14:38"
["CreateBy"]=>string(5)"admin"
["ROW_NUMBER "]=>string(1)"1"
}
array(1){
[0]=>array(6){
["ID"]=>int(1 )
["TechLevel"]=>string(2)"10"
["Remark"]=>string(4)"��"
["CreateDate"]=>string(19) "2013-03-1415:14:38"
["CreateBy"]=>string(5)"admin"
["ROW_NUMBER"]=>string(1)"1"
}
}
As can be seen from the above code, find() returns a one-dimensional array, and select() returns a two-dimensional array, so there are differences in the values. For one-dimensional arrays, use $data["TechLevel" ], use $data[0]["TechLevel"] to get the value of the two-dimensional array. Since I didn't understand this usage at the beginning, I couldn't get the value even after debugging for a day. Finally, I saw the difference between the two methods after using the dump method!
In addition,
$Model=M();
$sql='selectroleidfrom'.C("DB_PREFIX").'adminwhereuserid='.session('userid').'';
$list=$ Model->query($sql);
//Writing method 1
foreach($listas&$info){
if(info['roleid']=='1'){
}
//Writing method two
if($list[0]['roleid']=='1'){
}
thinkphp's original sql spelling, the result is also a two-dimensional array