简体   繁体   English

我的代码出了点问题,我也不知道,

[英]Something is wrong with my code and i don't know what,

i'm trying to figure this out for days and i can't find what the error might be. 我试图解决这几天,我找不到错误可能是什么。

This is my code: 这是我的代码:

<?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;


include 'conn.php';




class get_data extends connection{

    public function __construct($page,$rows){
        $s_page=mysql_real_escape_string($page);
        $s_rows=mysql_real_escape_string($rows);



        $this->get_all($s_page,$s_rows);

    }


    public function get_all($page,$rows){
    $this->connect_to_db();
    $tablename = $this->define_table_name();
    $offset = ($page-1)*$rows;
    $result = array();


    $rs = mysql_query("select count(*) from $tablename");
    $row = mysql_fetch_row($rs);
    $result["total"] = $row[0];
    $startq="select * from $tablename limit $offset,$rows"; 
    $rs = mysql_query("select * from $tablename limit $offset,$rows");
    $items = array();
    while($row = mysql_fetch_object($rs)){
    array_push($items, $row);
    }
    $result["rows"] = $items;

    echo json_encode($result);


    }

}

 $getdata=new get_data($page,$rows);
 ?>

The Output is {"total":"3","rows":[]} 输出为{"total":"3","rows":[]}
THE PROBLEM IS: the rows are empty but it counts how many rows are in the db meaning that the connection is good but the query for the row is not working any suggestions? 问题是:行为空,但它计算数据库中有多少行,这意味着连接良好,但对行的查询没有任何建议?

You are mysql_real_escape_string ing your parameters before establishing a connection to the database. 建立与数据库的连接之前,您正在mysql_real_escape_string参数。 mysql_real_escape_string needs an existing connection to the database to do its job. mysql_real_escape_string需要与数据库的现有连接才能完成其工作。 If there is none, it'll try to establish a connection by itself, which most likely fails, which means your parameters are null . 如果不存在,它将尝试自行建立连接,这很可能失败,这意味着您的参数为null

That should've been easy to figure out if you'd've enabled error reporting or would have debugged your app by simply var_dump ing various variables here and there. 如果您已经启用了错误报告功能,或者只是通过var_dump到处乱码各种变量来调试应用程序,那应该很容易弄清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Mixpanel API 用于 Laravel,我认为我的代码缺少一些东西,但我不知道是什么 - Using Mixpanel API for Laravel, I think my code is missing something, but I don't know what 我不知道这段代码SQL有什么问题 - I don't know what's wrong with this code SQL 我破坏了代码,不知道发生了什么 - I broke my code and don't know what happened 我正在尝试制作一个登录页面。 然而,事情总是出错 - 我不知道是什么? - I am trying to make a login page. However something keeps going wrong - and I don't know what? 我正在尝试在表中显示数据库中的数据,但不想出现,也不知道出了什么问题 - I'm trying to display data from my database in table, but don't want to appear, I don't know what went wrong 我不知道联系表有什么问题 - I don't know what's wrong with contact form 我的 session 代码有问题,我不知道发生了什么? - I have some problem in my code with session and I don't know what is going on? 我的代码在哪里错误? 我没有收到任何电子邮件 - Is my code wrong somewhere? I don't get any email 我正在尝试将直接<a>链接到</a> <td> <a>但我不知道怎么了</a> - I'm trying to put a direct <a> to a link inside a <td> but I don't know what's wrong 我不知道在使用Volley更新数据库时我做错了什么 - I don't know what am I doing wrong in updating database using Volley
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM