开发者

Flex: How to pass these parameters to my PHP remote service?

开发者 https://www.devze.com 2023-03-09 16:37 出处:网络
Consider the following query which works in MySql: SELECT r.restaurantId, name, city FROM restaurant AS r,

Consider the following query which works in 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

This is the method on the remote service (PHP) I am trying to call:

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, na开发者_如何学Pythonme, city, phone ORDER BY name");
// some other stuff here
}

I've have successfully connected to this remote service from the Flex Data services. What I cannot figure out is how to execute the above query from within Flex. E.g. I've tried

var array1:Array = new Array();
array1[0] = 6;
array1[1] = 10;

and I've tried

var string1:String = new String("6,10");

calling the remote function like so

remoteService.getRestaurantsByCategories(array1);

or so

remoteService.getRestaurantsByCategories(string1);

and so

remoteService.getRestaurantsByCategories(array1.join(","));

but all of these only return matches for categoryId=6.

What's the right way to pass the parameters to PHP so that the query gets executed for both categoryIds?

Thanks for any help, folks.


You're not using any kind of remoting framework like AMFPHP or ZendAMF. It's impossible to call a PHP function from the outside since it's out of scope. When a PHP script runs, it runs whatever is in the outside of the functions which could then call the functions themselves.

Still, I recommend you use AMFPHP or ZendPHP to do this part.


Have you tried the following:

  1. try to set in flex/as3 var string1:String = new String(" 6 , 10 "); instead of just "6,10". It may be possible that your string is converted to other type... like int("6,10") ~= 6.

  2. Have you tried to force a cast to string on $categories ?

  3. Have you put a trace/echo on the $categories value in php? do you get 6,10 ?

  4. Can you try to replace the query with:

    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
    }
    
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号