0

My code is returning nothing. I can't understand what the problem is.

my code

$results = $mysqli->query("SELECT * FROM tbl_pdf ORDER BY id DESC");

    $dataarray = array();
    while($row =mysqli_fetch_array($results))
    {

        $dataarray [] = [
            'id'=>$row['id'],
            'ptitle'=>$row['ptitle'],
            'pdate'=>$row['pdate'],
            'filelink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.$row['filelink'],
            'status'=>$row['status']
        ];

    }

    echo json_encode($dataarray);
buczek
  • 2,011
  • 7
  • 29
  • 40
Ponly1991
  • 1
  • 1
  • Are you connected to correct database? This script must return at least `[]` if there are not errors. – vp_arth May 23 '16 at 16:42
  • 4
    Have you tried checking for MySQL errors? You can't always assume your MySQL queries have worked. `if($results === false){ die($mysqli->error); }` – gen_Eric May 23 '16 at 16:42
  • 3
    P.S. It doesn't really matter but it's a good idea to be consistent on whether you are using OOP or the procedural method. `while($row = $results->fetch_array())` – gen_Eric May 23 '16 at 16:44
  • yes.database connected correctly @vp_arth – Ponly1991 May 23 '16 at 16:44
  • 2
    make sure you have error reporting enabled http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Jeff Puckett May 23 '16 at 16:44
  • 2
    Posting a live link to this page doesn't really add anything useful to the question. The PHP's ran on the server, so all we see is the (blank) output. – gen_Eric May 23 '16 at 16:46
  • 2
    That link does show a 500 so you are getting an error of some sort. Check your error logs, enable logging. – chris85 May 23 '16 at 16:48
  • @chris85: I guess the link *was* useful then :) – gen_Eric May 23 '16 at 16:50
  • It's actualy not live it's dead link =) – vp_arth May 23 '16 at 16:52

0 Answers0