[英]PHP is concatenating instead of adding
I'm having this problem where my PHP code is concatenating instead of adding 我在连接我的PHP代码而不是添加的地方遇到了这个问题
$offset=$_POST['offset']; //Get the offset
$searchLimit = 10;
$searchCount = count(sql) //For the purpose of this question, it returns the result count
Now I want to calculate the 'from' display for pagination, so I do 现在,我想计算分页的“从”显示,所以我这样做
$from = ($offset*$searchLimit)+1;
It works fine when 它在以下情况下可以正常工作
$offset == 0
$偏移== 0
I get the expected result which is 1. But when 我得到的预期结果是1。但是当
$offset == 1
$偏移= = 1
It gives me 101. Basically it is concatenating the 10 and 1 to give me 101. I've tried the following 它给了我101。基本上是将10和1连接在一起给我101。我已经尝试了以下方法
$from = (int)($offset*$searchLimit)+1
$from = ((int)($offset)*$searchLimit)+1
$from = (((int)($offset)*$searchLimit)+1)
I even tried 我什至试过
$offset = (int)$_POST['offset'];
But all of them are giving the same result. 但是所有这些都给出了相同的结果。
You are missing a $
before searchLimit
. 您在
searchLimit
之前缺少$
。 As a result, it is being treated as a string. 结果,它被视为字符串。 This result in unexpected behaviour.
这会导致意外的行为。
You missed a $ sign before searchLimit (and perhaps before sql). 您在searchLimit之前(可能在sql之前)错过了$符号。 -_-
-_-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.