我試圖從mysql數據庫獲取值並從php創建json。但我總是得到「虛假」的答覆。嘗試編碼json時出現錯誤php
我的查詢運行正常。
<?php
header("Content-type: text/html; charset=utf-8");
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
$charset="UTF8";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sth = mysqli_query("select
a.id,
a.fname,
a.mname,a.lname,a.country,a.city,a.dob,a.role,
a.email,
b.mobile,b.skypeid,b.address,b.languages,
c.height,
c.width,
c.skin,
c.bust,
c.waist,
c.hips,
c.shoesize,
c.hair,
c.eye,
c.comments,
d.movie,
d.advertisement,
d.brandpromotional,
d.danceshow,
d.runway,
d.catalog,
d.editorial,
d.fit,
d.casual,
d.corporate,
d.swimwear,
d.fitness,
d.magazine,
d.lingerie,
d.glamour,
d.alternative,
d.hair,
d.legs,
d.hands,
d.webmodel,
d.social,
d.experience
from
basicinfo a
join contactdetails b
on a.email=b.email
join measurements c
on a.email = c.email
join areainterest d
on a.email=d.email
where a.role='Model'");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
請幫我
你什麼你json_encode之前獲得,當你'的var_dump($行)'對不對? –
可能重複的[json \ _encode()返回false](http://stackoverflow.com/questions/19440529/json-encode-returns-false) –
我得到這一個數組(0){} – Bangalore