PhP を使用して mysql からデータを取得しようとしています。PHPファイルをテストしているだけです。これが機能する場合は、それらの結果を Android アプリに取得する作業を開始します。
表示される PHP の結果は常に null です。データベースでデータが利用可能であることを確認できます。
DATABASE には次のテーブルがあります。
人口 - フィールドは次のとおりです: id、性別、都市、州
結果は常に次のとおりです。
{"success":1,"data":[{"id":null,"gender":null,"city":null,"state":null}]}
コードの何が問題なのかわかりません:
<?php
include("db_config.php");
$response = array();
$gender = 'Male';
// get a product from products table
$result = mysql_query("SELECT * FROM population WHERE gender = '$gender'");
if (!empty($result))
{
// check for empty result
if (mysql_num_rows($result) > 0)
{
$result = mysql_fetch_array($result);
$data = array();
$data ["id"] = $row["id"];
$data ["gender"] = $row["gender"];
$data ["city"] = $row["city"];
$data ["state"] = $row["state"];
// success
$response["success"] = 1;
$response["data"] = array();
array_push($response["data"], $data);
echo json_encode($response);
}
else
{
$response["success"] = 0;
$response["message"] = "No data found";
echo json_encode($response);
}
}
else
{
$response["success"] = 0;
$response["message"] = "No data found";
echo json_encode($response);
}
?>
誰かがこのphpコードで私を助けることができますか? 過去 3 日間、これに取り組んできましたが、解決策が得られませんでしたか?
ありがとう!