考虑以下在MySql中有效的查询:
SELECT r.restaurantId, name, city FROM restaurant AS r,
restaurant_restaurant_category AS c
WHERE r.restaurantId = c.restaurantId AND categoryId IN (6, 10)
GROUP BY restaurantId, name, city, phone ORDER BY name
这是我试图调用的远程服务(PHP)上的方法:
public function getRestaurantsByCategories($categories) {
$stmt = mysqli_prepare($this->connection,
"SELECT r.restaurantId, name, city FROM restaurant AS r,
restaurant_restaurant_category AS c
WHERE r.restaurantId=c.restaurantId AND categoryId IN (?)
GROUP BY restaurantId, name, city, phone ORDER BY name");
// some other stuff here
}
我已成功从Flex Data服务连接到此远程服务。我无法弄清楚如何从Flex中执行上述查询。例如。我试过了
var array1:Array = new Array();
array1[0] = 6;
array1[1] = 10;
我试过
var string1:String = new String("6,10");
像这样调用远程函数
remoteService.getRestaurantsByCategories(array1);
左右
remoteService.getRestaurantsByCategories(string1);
等等
remoteService.getRestaurantsByCategories(array1.join(","));
但所有这些只会返回categoryId=6
的匹配项。
将参数传递给PHP的正确方法是什么,以便categoryIds
执行查询?
感谢任何帮助,伙计们。
答案 0 :(得分:0)
您没有使用任何类型的远程处理框架,如AMFPHP或ZendAMF。从外部调用PHP函数是不可能的,因为它超出了范围。当PHP脚本运行时,它会运行函数外部的任何内容,然后可以自己调用函数。
答案 1 :(得分:0)
您是否尝试过以下操作:
尝试设置flex / as3 var string1:String = new String(“6,10”); 而不只是“6,10”。 您的字符串可能会转换为其他类型... 喜欢int(“6,10”)〜= 6.
您是否尝试在$ categories上强制转换为字符串?
您是否在php中的$ categories值上添加了trace / echo?你得到6,10?
您可以尝试将查询替换为:
public function getRestaurantsByCategories($categories)
{
$stmt = mysqli_prepare($this->connection,
"SELECT r.restaurantId, name, city FROM restaurant AS r,
restaurant_restaurant_category AS c
WHERE r.restaurantId=c.restaurantId AND categoryId IN ($categosies)
GROUP BY restaurantId, name, city, phone ORDER BY name");
// some other stuff here
}