带限制的php mysql select语句

带限制的php mysql select语句,php,mysql,Php,Mysql,我一直收到这个错误,但是这个sql语句在mysql中运行得很好。它可能有点愚蠢,但我整个周末都在做它,所以我累坏了 select e.* , t.nombre , c.compania , c.nombre , c.apellido , c.ruc , c.direccion from envio e inner join cliente c on e.cliente_id = c.id inner join transporte t on t.id = e.transporte

我一直收到这个错误,但是这个sql语句在mysql中运行得很好。它可能有点愚蠢,但我整个周末都在做它,所以我累坏了

select e.* 
, t.nombre
, c.compania 
, c.nombre 
, c.apellido 
, c.ruc 
, c.direccion 
from envio e 
inner join cliente c on e.cliente_id = c.id 
inner join transporte t on t.id = e.transporte_id 
limit 0, 10;

MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0, 10' at line 11
下面是var_转储结果:

string(263) "select e.* , t.nombre as transporte_nombre , c.compania , c.nombre , c.apellido , c.ruc , c.direccion from envio e inner join cliente c on e.cliente_id = c.id inner join transporte t on t.id = e.transporte_id limit 0, 10" MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 0, 10' at line 11
这是我的代码,现在我使用了两个类,一个是我的db连接,工作正常(用其他页面测试),另一个是返回select的

if(!empty($_REQUEST['page']))
    $page = $_REQUEST['page'];
else
    $page = "1";

$limit = 10;    
if($page)
    $start = ($page - 1) * $limit; 
else
    $start = 0; 

require_once("../class/sql.php");
$db = new MySQL();  

require_once("../class/envios.php");
$envios = new Envio();
var_dump($envios->BuscaEnvios("",$start,$limit));

if(is_array($conditions))
    $consulta = $db->consulta($envios->BuscaEnvios($conditions,$start,$limit));  
else
    $consulta = $db->consulta($envios->BuscaEnvios("",$start,$limit));  

if($db->num_rows($consulta) > 0)
    $total_pages = $db->num_rows($consulta);
else 
    $total_pages = 0;
在“Envios”课程中:


在函数中尝试此代码

if(sizeof($conditions)>0)
          {
            $sql .= " where ".implode(' AND ', $conditions);
          }

        $sql .= " limit $start, $limit";

在函数中尝试此代码

if(sizeof($conditions)>0)
          {
            $sql .= " where ".implode(' AND ', $conditions);
          }

        $sql .= " limit $start, $limit";


限制0,10基本上是说“返回0行,从第10行开始”。我想你想让它们反过来?@GordonM这不正确,0(开始),10(行)。@GordonM语法读作
limit 10 offset 0
;当我通过phpadmin在mysql中使用相同的语句时,它显示了10条记录0-9,但我改变了它,仍然没有区别:(@Andreas你能用PHP来var_转储sql吗?我怀疑是某种空白。0,10基本上是说“返回0行,从第10行开始”。我想你想让它们反过来?@GordonM这不正确,0(开始),10(行)。@GordonM语法读作
limit 10 offset 0
;当我通过phpadmin在mysql中使用相同的语句时,它显示10条记录0-9,但我将其切换,仍然没有区别:(@Andreas你能用PHP来var_转储sql吗?我怀疑这是某种空白,但我在调用函数之前使用了sizeof($condition)。因此,当我转到该函数时,我只需检查$condition!=“”:)谢谢大家,因为每一条评论都让我离修复它更近了一步!@Andres if condition是一个数组,为什么不说
if(count($conditions))
?-1对于丑陋的限制偏移量用法,这个
limit$limit offset$start
不是更有意义吗?(这是标准SQL)我想这也会起作用@Mario只是我需要完成这件事,这是我花了几个小时做的第一件事。无论如何,谢谢。限制$start,$limit我得到了,因为我的分页代码就是这样使用的,我认为Punit只是复制了我拥有的,没有真正的理由否决。这很有效,但我使用了大小调用函数之前,先检查($condition)。因此,当我转到该函数时,我只需检查$condition!=“”:)谢谢大家,因为每个注释都让我离修复它更近了一步!@Andres如果condition是数组,为什么不说
if(count($conditions))
?-1对于丑陋的限制偏移用法,此
限制$limit offset$start
是否更有意义?(并且是标准SQL)我想这也会起作用@Mario只是我需要完成这件事,这是我花了几个小时做的第一件事。无论如何,谢谢。我得到的限制$start,$limit是因为我的分页代码就是这样使用的,我认为Punit只是复制了我拥有的,没有真正的理由否决。