如何对此 $sql 进行选择计数查询?
我需要这个查询:
$sql = "
SELECT STRAIGHT_JOIN DISTINCT
table1.pid, table1.fn, table2.did_id, table2.whodoc, table3.nname, table3.nid
FROM table1
JOIN table4 ON table1.pid = table4.pid
JOIN table2 ON table4.did_id = table2.did_id
JOIN table3 ON table1.pid = table3.pid
WHERE kind = '$kind'
AND (
(table3.nname LIKE '%$q%'
OR table3.pat_notes LIKE '%$q%'
OR table3.nid like '%$q%')
)
ORDER BY table3.id DESC
LIMIT $startrow, 10
";
以这种格式重写:
$result = mysql_query("
SELECT *
FROM some table
LEFT JOIN other_table ON something.some_id = somesometable.somesomeid_id
WHERE atable.a1field = '$something'
OR the_atable.a2table_by = '$ok'
AND privacy = '$sorter'
AND the_visit.why_visit LIKE '%$q%'
OR the_visit.height_onv LIKE '%$q%'
OR the_visit.blood_pressure_onv LIKE '%$q%'
");
$num_rows = mysql_num_rows($result);
I need this query:
$sql = "
SELECT STRAIGHT_JOIN DISTINCT
table1.pid, table1.fn, table2.did_id, table2.whodoc, table3.nname, table3.nid
FROM table1
JOIN table4 ON table1.pid = table4.pid
JOIN table2 ON table4.did_id = table2.did_id
JOIN table3 ON table1.pid = table3.pid
WHERE kind = '$kind'
AND (
(table3.nname LIKE '%$q%'
OR table3.pat_notes LIKE '%$q%'
OR table3.nid like '%$q%')
)
ORDER BY table3.id DESC
LIMIT $startrow, 10
";
To be rewritten in this format:
$result = mysql_query("
SELECT *
FROM some table
LEFT JOIN other_table ON something.some_id = somesometable.somesomeid_id
WHERE atable.a1field = '$something'
OR the_atable.a2table_by = '$ok'
AND privacy = '$sorter'
AND the_visit.why_visit LIKE '%$q%'
OR the_visit.height_onv LIKE '%$q%'
OR the_visit.blood_pressure_onv LIKE '%$q%'
");
$num_rows = mysql_num_rows($result);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于无法访问实际数据,我相信您可以执行以下操作:
不太确定
STRAIGHT_JOIN
部分,因为我还没有这样做。但其余的我认为应该有效。Not having access to the actual data, I believe you could do something like this:
Not real sure about the
STRAIGHT_JOIN
part, since I've not done that. But the rest I think should work.