0

How do i go ahead to output mysql row to a var array like this

 var data = [

            {"name" : "mysql data", "hvalue" : mysql data number },

        ];

all the possible mysql rows not just 1

Brad M
  • 17
  • 2
  • 5

1 Answers1

0

Sounds like just altering the array you are building out... So you can encode your db result

$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
    $rows[] = $r;
}
print json_encode($rows);//will return your desired data

The function json_encode needs PHP >= 5.2 and the php-json package - as mentioned here

NOTE: mysql is deprecated as of PHP 5.5.0, use mysqli extension instead http://php.net/manual/en/migration55.deprecated.php.

Community
  • 1
  • 1
Hudhaifa Yoosuf
  • 869
  • 2
  • 12
  • 28