0
我正在通過PHP腳本從Android到達MySQL數據庫,我正在使用JSON解析返回的值。它工作正常。我的問題是關於MySQL。MySQL表和JSON解析。外鍵還是不?
我有兩個表名爲country
和geography
,它們的結構如下。
國家表中有這些列:
country_id* | country_name and 20 more column...
地理表中有這些列:
geography_id* | location and 15-20 more column...
(*)表示主鍵
<?php
//some connection properties here....
// PHP variable to store the result of the PHP function 'mysql_connect()' which establishes the PHP & MySQL connection
$db_con = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');
mysql_select_db($db_name);
$sql = "SELECT * FROM countries, geography WHERE country_id = '". $_POST["COUNTRY_ID"]."'";
$result = mysql_query($sql);
while($row=mysql_fetch_assoc($result))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
運行此腳本後返回不需要的值。假設,當我請求country_id = 1
JSON返回geography
表的所有行。我只想檢索geography_id=1
的行。我必須使用外鍵來解決我的問題。或者另一種方式?
WHERE COUNTRY_ID =「...」 AND geography_id = 1 – ChristopheCVB 2013-04-07 22:40:56
我試過你的解決方案。但JSON只返回第一行。 – hakiko 2013-04-07 22:44:44
2個表格之間的聯繫是什麼? – ChristopheCVB 2013-04-07 22:45:54