mysqli - getting the 1st row in a database
问题描述
I want to get the 1st row of the result depends on which build the room is. For example Building 1 have 1-200 rooms and Building 2 have 201-400 rooms. The code I tried is below. I have used the MIN in the where clause but I got all the rooms instead of having one.
$query = $this->db->query("SELECT * FROM `ha_utility_reading`");
if ($query->num_rows == 0) {
echo "some data match";
$lastroom = $this->db->select("*")->from("rooms")
->where("(SELECT MIN(room_num) FROM ha_rooms) and bldg_num = '$bldg_num'")
->get()->result_array();
foreach($lastroom as $key => $test) {
$output['room_num'][] = $test['room_num'];
json_encode($output);
}
解决方案
尝试这个,
select * from rooms order by room_num asc limit 1;
推荐阅读
- arraylist - 如何将 ArrayList 传递给构造函数?
- json - 从 VB.Net 中的 Json 数组获取值
- flutter - 颤振中的自定义日期选择器
- python - 如何将表单的数据(从 HTML 页面的函数中检索)发送到 Django/Python 中另一个 HTML 页面的函数?
- amazon-web-services - 在 AWS Lambda 上使用 Node.js Express 的对等证书
- c++ - 如何直接访问类的私有成员?
- sql - 如果条件,sqlite 创建值为 1 的列
- python - 矩形在显示 PyGame 上不移动
- linux - WSL:如果使用符号链接,则无法在 Windows 资源管理器中查看文件夹(显示为文件),但如果符号链接在同一目录上则有效
- .htaccess - 如何在 htaccess 中将 url index.html 重写为 /home