[英]PHP SQL Query Mystery
This headache of a sql massage thrwos no error, but the $zvv variable is not being inserted properly in the query, it is like affecting the result as if it is "" nothing BUT it does have a valid string value, but it is not getting into the query.这种令人头疼的 sql 按摩 thrwos 没有错误,但是 $zvv 变量没有正确插入查询中,就像影响结果一样,好像它是 "" 什么都没有,但它确实有一个有效的字符串值,但它不是进入查询。
See any problem with this sql?看到这个 sql 有什么问题吗?
$sqlQuery = " SELECT * FROM tbl_staff WHERE status =' " . $zvv . " ' limit
" . ($lowerLimit) . " , " . ($perPageCount) . " ";
Try this:尝试这个:
"SELECT * FROM tbl_staff WHERE status='$zvv' LIMIT
$lowerLimit , $perPageCount ";
Should do the trick.应该做的伎俩。
You have spaces in your concatenation.您的串联中有空格。 Also if you use double quotes, the content of the variable will be printed out.
此外,如果使用双引号,变量的内容将被打印出来。
$sqlQuery = "
SELECT *
FROM
tbl_staff
WHERE
status ='$zvv'
LIMIT
$lowerLimit , $perPageCount ";
You have spaces in your query:您的查询中有空格:
$sql = " SELECT * FROM tbl_staff WHERE status =' " . $zvv . " ' limit " . ($lowerLimit) . " , " . ($perPageCount) . " ";
-----^ -----^
So if $zvv
has a value of 'abc'
you're using it in the query as status=' abc '
which, because of the spaces, isn't the same.因此,如果
$zvv
的值为'abc'
您在查询中使用它作为status=' abc '
,由于空格的原因,它是不一样的。 Cleaned up result, this is how I prefer to write it:清理结果,这是我更喜欢的写法:
$sqlQuery = "SELECT * FROM tbl_staff
WHERE status='". $zvv ."'
LIMIT ". $lowerLimit.",".$perPageCount;
Thanks, got 2 birds with one stone here, some of this oughta work better than my current query, and prepared statements seem like a good permanent way to get past wrestling characters with this trial and error approach and that more safely from SQL injection risk.谢谢,这里有 2 只鸟,其中一些应该比我当前的查询更好,并且准备好的语句似乎是一种很好的永久方式,可以通过这种反复试验的方法克服摔跤角色,并且更安全地避免 SQL 注入风险。
That error was holding up the rest of the routine in a deceptive manner where it seemed to work until I looked closer, as this is the first time I messed with AJAX and pagination.这个错误以一种欺骗性的方式阻碍了例程的其余部分,在我仔细观察之前它似乎可以工作,因为这是我第一次弄乱 AJAX 和分页。
This advice oughta save some real sql-roulette headache time immensely in the future, it is pretty finicky but I understand why now.这个建议应该在未来极大地节省一些真正的 sql-roulette 头痛时间,它非常挑剔,但我现在明白为什么了。
Thanks everyone.谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.