0

This is my php script for fetching data from a db.

<?php

    mysql_connect("host","user","pass");

    mysql_select_db("db");

  $q=mysql_query("SELECT * FROM examples ")or die(mysql_error());

          $output[]=mysql_fetch_array($q,11);;

       print(json_encode($output));

mysql_close();?>

I have renamed the host and so on for obvious reasons. Isn't this code supposed to get me all the rows from the examples table? It justs brings me the first row... Why that?

Stefan Bossbaly
  • 6,682
  • 9
  • 53
  • 82
qwerty_gr
  • 318
  • 3
  • 7
  • 15

1 Answers1

3

Did you read the docs? :)

Use the following code to get all rows:

$output = array();
while($row = mysql_fetch_array($q)) {
    $output[] = $row;
}

You might want to use mysql_fetch_assoc() or mysql_fetch_object() though so you don't have the (rather useless) numeric indexes in the resultset.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • sorry for it. I took a look but I didn't see that there is a similar post. you can erase it if you want. – qwerty_gr Mar 20 '12 at 23:50