MySQL查询给出除零错误

时间:2014-08-08 06:49:36

标签: php mysql

我有这个SQL查询

$sql =  'SELECT id, texto FROM `db_name`.`table_name` WHERE ( CONVERT( `texto` USING utf8 ) LIKE '%q%' ) ORDER BY score DESC LIMIT 0,15';

我收到以下错误

Warning division by zero at line 40 

Query was empty

虽然当我将相同的查询复制到我的phpmyadmin终端以获取sql并在那里进行查询时,它会给出结果

更新

function get()
        {
            $sql =  'SELECT id, texto FROM `db_name`.`table_name` WHERE ( CONVERT( `texto` USING utf8 ) LIKE '%fincas%' ) ORDER BY score DESC LIMIT 0,15';


            $rc= $this->parent->parent->database->query($sql);

            $post='';
            while($row= $this->parent->parent->database->readRows($rc))
            {
                echo $post;
                echo str_replace('"','"',$row['texto']).'"'.$row['id'];
                $post="\n";
            }

        }

1 个答案:

答案 0 :(得分:4)

第一个错误是你的php错误检查你在第40行执行一些数学部门的PHP代码

第二个错误是由于在sql查询'%q%'中使用单引号。通过在双引号中引用sql字符串来纠正它

$sql =  "SELECT id, texto FROM `db_name`.`table_name` WHERE ( CONVERT( `texto` USING utf8 ) LIKE '%q%' ) ORDER BY score DESC LIMIT 0,15";