我是php webservices的新手。我希望获得以下格式的sql数据:

我使用的SQL查询是:
$result = mysql_query("select r.id,r.Name, o.`Title`, o.id, o.`Description`, o.`OfferLocation`
from `restaurants` r left join `offers` o on r.id = o.`restaurant_id`");通过这个查询,我为每个唯一的restaurant获得了冗余的offer名称,这很好。但是,如何将图像中给定的数据格式化为多维数组呢?
以下是我到目前为止尝试过的代码:
if(mysql_num_rows($result) > 0){
$response["restaurant"] = array();$cnt=0;
$item_rest=array();
while($row=mysql_fetch_array($result)){
$item_rest["RestaurantID"]=$row["id"];
}
$response_offer["offers"]=array();
while($row=$result->fetch_array($result)){
$item = array();
$item["Offer"]= $row["Title"];
$item["OfferId"]= $row["id"];
$item["Description"]= $row["Description"];
$item["OfferLocation"]= $row["OfferLocation"];
array_push($response_offer["offers"],$item);
}
array_push($response["restaurant"],$response_offer);
$response["success"]=1;
}我该怎么做呢?
发布于 2014-10-03 17:55:06
我认为您正在尝试同时使用两个API,尝试将$result->fetch_array($result) (mysqli)改为mysql_fetch_array($result) (mysql)。
考虑停止使用mysql_函数,因为它们已被弃用,更多的here
https://stackoverflow.com/questions/26176331
复制相似问题