Search code examples
androidjsonparsingampersand

how to pass and fetch data when using ampersand in sql


im trying to pass a url to fetch data for android JSON.

The url is: fetch_cat_url = "xxx/get_product_details.php?task_name=get_cat&cat_name="+cat_name;

where cat_name="Books & More"
now when i pass this url.. it goes like

xxxxx/get_product_details.php?task_name=get_cat&cat_name=Books & More

in my sql file
switch($_GET["cat_name"])
        {
            case "Fashion":
            $sql = "SELECT * FROM `category` where c_name IN (\"Men\",\"Women\" ,\"Baby & Kids\") ";
            break;

            case "Home & Living":
            $sql = "SELECT * FROM `category` where c_name IN (\"Kitchenware\", \"Home Furnishing\", \"Home Decoratives\", \"Furniture\") ";
            break;

            case "Books & More":
            $sql = "SELECT * FROM `category` where c_name IN (\"Academic Text\", \"Literature & Fiction\", \"Non Fiction\", \"Self Help\", \"Children & Young Adult\", \"Competitive Exam\") ";
            break;

            case "Automotives":
            $sql = "SELECT * FROM `category` where c_name IN (\"Car Accessories\", \"Helmets & Accessories\", \"Car & Vehical Electronics\", \"Car Freshners\", \"Spare Parts\") ";
            break;
        }

now for & the data is not returned in json.. but it returns for rest all categories...

data returns for fashion and automotives but not for books and home


Solution

  • while passing cat_name in json from client side make sure that the json string should be encoded like this .

    String jsonString = Uri.EncodeDataString(json)
    

    now just pass jsonString to server.. may be it will help full.