jquery - Passing Data MySQL -> PHP -> JSON -


i'm trying make php web service can data mysql db on webspace @ school, , parse data json. call php function jquery, seems php returns empty array.

here php code:

    <?php    // create connection $con=mysqli_connect("mysqlstudent","sylvainvansteela","zei8quea0eep","sylvainvansteela");  if (mysqli_connect_errno($con))  {   echo "failed connect mysql: " . mysqli_connect_error();   } else {  $mysqlstring = "select * customers";  $result = mysqli_query($con,$mysqlstring); $rows = array();  while($r = mysql_fetch_array($result)) {   $rows["id"] = $r[0];   $rows["email"] = $r[1]; }   header("content-type: application/json"); echo json_encode($rows);  }   ?> 

and here jquery code:

function getcustomers(){

    var url = 'http://student.howest.be/sylvain.vansteelandt/fedex/server/getcustomers.php';      $.getjson(url,function(data){      if(data){         alert(data);         console.log(data.length);     } else {         alert('error');     }    });  };  getcustomers(); 

i recommend changing following part of php:

$rows = array();  $i = 0; // add while($r = mysqli_fetch_array($result)) { // mysqli!   $rows[$i]["id"] = $r[0];   $rows[$i]["email"] = $r[1];   $i++; // don't forget increment } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -