1

当我获取 aasoc 时,我需要从其他表中进行 4 次选择。它非常糟糕并且停止了驱动页面(。请告诉我是否可以提出一个请求而不是四个请求?

$sql_id_city = "SELECT * FROM City WHERE id_city='$id_city'";
$get_id_city = sqlsrv_query($conn, $sql_id_city);
$info_id_city = sqlsrv_fetch_array($get_id_city, SQLSRV_FETCH_ASSOC); 
$name_city=$info_id_city['name'];


$id_producer_country=($i['id_producer_country']!='')? $i['id_producer_country']:'0';

$sql_id_producer_country = "SELECT * FROM Producer_country WHERE id_producer_country='$id_producer_country'";
$get_id_producer_country = sqlsrv_query($conn, $sql_id_producer_country);
$info_producer_country = sqlsrv_fetch_array($get_id_producer_country, SQLSRV_FETCH_ASSOC);
$name_producer_country=$info_producer_country['name'];



$id_firm=($i['id_firm']!='')? $i['id_firm']:'0';

$sql_id_firm = "SELECT * FROM Firm WHERE id_firm='$id_firm'";
$get_id_firm = sqlsrv_query($conn, $sql_id_firm);
$info_film = sqlsrv_fetch_array($get_id_firm, SQLSRV_FETCH_ASSOC);
$name_firm=$info_film['name'];
$phone_firm=$info_film['phone'];

$id_price=($i['id_price']!='')? $i['id_price']:'0';

$sql_id_cost = "SELECT * FROM Cost WHERE id_price='$id_price'";
$get_id_cost = sqlsrv_query($conn, $sql_id_cost);
$info_cost = sqlsrv_fetch_array($get_id_cost, SQLSRV_FETCH_ASSOC);
$cost=$info_cost['cost'];
$id_currency=$info_cost['id_currency'];
$id_sale=$info_cost['id_sale'];
4

1 回答 1

0
    "SELECT * FROM City , Producer_country , Firm , Cost WHERE City.id_city='$id_city'
 AND Producer_country.id_producer_country=City.'$id_producer_country(country id as field in city table)' 
AND Firm.id_firm='$id_firm(fiels name as u in Producer_country table )' AND
 Cost.id_price='$id_price(fiels name as u in firm table)'"


if u have same as fiels in other table so u can use the as keyword for avoid the ambiguity 
于 2012-12-07T06:16:47.393 回答