doutao4938 2013-01-06 01:51
浏览 71

PHP是连接而不是添加

I'm having this problem where my PHP code is concatenating instead of adding

$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

I get the expected result which is 1. But when

$offset == 1

It gives me 101. Basically it is concatenating the 10 and 1 to give me 101. I've tried the following

$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.

  • 写回答

2条回答 默认 最新

  • dongzg2006 2013-01-06 01:56
    关注

    You are missing a $ before searchLimit. As a result, it is being treated as a string. This result in unexpected behaviour.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入