[英]PHP Mysql LIMIT failing in query
I am trying to get messages with a joined query with 3 tables everything works fine as expected but when i am trying to limit the results the query is failing and not returning anything 我正在尝试通过包含3个表的联合查询来获取消息,一切都按预期工作,但是当我尝试限制结果时,查询失败并且不返回任何内容
query 询问
SELECT
P.patient_name,
DM.message,
DM.secsince,
DM.id,
DM.pid,
DM.did,
DM.mode,
DM.date,
DM.seen
FROM tbl_patient P,
tbl_doct D,
tbl_doct_messages DM
WHERE (DM.did = D.id AND DM.pid = P.id)
AND (DM.mode = 'in')
AND (D.id = '$id')
ORDER BY DM.secsince DESC;
This query works fine and gives me expected results 该查询工作正常,并给了我预期的结果
but when I use LIMIT it is failing and not returning anything for some reason 但是当我使用LIMIT时,它由于某些原因而无法返回任何内容
query 询问
SELECT
P.patient_name,
DM.message,
DM.secsince,
DM.id,
DM.pid,
DM.did,
DM.mode,
DM.date,
DM.seen
FROM tbl_patient P,
tbl_doct D,
tbl_doct_messages DM
WHERE (DM.did = D.id AND DM.pid = P.id)
AND (DM.mode = 'in')
AND (D.id = '$id')
ORDER BY
DM.secsince DESC;
LIMIT=1;
here is the whole php code 这是整个PHP代码
<?php
include("conn.php");
if(mysqli_connect_error($con)) {
echo "Failed To Connect";
}
$id = $_GET['id'];
$qry = "SELECT P.patient_name, DM.message, DM.secsince, DM.id, DM.pid, DM.did, DM.mode, DM.date, DM.seen
FROM tbl_patient P, tbl_doct D, tbl_doct_messages DM
WHERE (DM.did = D.id AND DM.pid = P.id) AND (DM.mode = 'in') AND (D.id = '$id')
ORDER BY DM.secsince DESC
LIMIT=1;";
$res = mysqli_query($con, $qry);
$flag = array();
while(($row = mysqli_fetch_array($res))){
array_push($flag, $row);
}
echo json_encode($flag);
mysqli_close($con);
?>
As you can see in this picture it gives me results without the limit 如您在这张图片中看到的,它给我带来了无限的结果
But no results so mysqli_fetch_array is failing when i add the limit 但是没有结果,所以当我添加限制时,mysqli_fetch_array失败
Why this happening ? 为什么会这样呢? i basically am out of ideas. 我基本上没有主意。
因为正确的语法是LIMIT 1
而不是LIMIT = 1
Update your query 更新查询
from 从
SELECT
P.patient_name,
DM.message,
DM.secsince,
DM.id, DM.pid,
DM.did, DM.mode,
DM.date, DM.seen
FROM
tbl_patient P,
tbl_doct D,
tbl_doct_messages DM
WHERE
(DM.did = D.id AND DM.pid = P.id) AND
(DM.mode = 'in') AND (D.id = '$id')
ORDER BY
DM.secsince DESC
LIMIT=1
to remove the = 删除=
SELECT
P.patient_name,
DM.message,
DM.secsince,
DM.id, DM.pid,
DM.did, DM.mode,
DM.date, DM.seen
FROM
tbl_patient P,
tbl_doct D,
tbl_doct_messages DM
WHERE
(DM.did = D.id AND DM.pid = P.id) AND
(DM.mode = 'in') AND (D.id = '$id')
ORDER BY
DM.secsince DESC
LIMIT 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.