Php 从移动应用请求的数据库查询结果
我正在将hybrid应用程序连接到web应用程序的API,以便在用户请求搜索后查询某些数据。我正在使用Onsen UI构建应用程序 服务器端的API代码应返回用户按其名称搜索的商户。结果应仅为1个商户(餐厅名称) 基本上,我从应用程序中发送一个参数名称“merchant”,API应该获取该参数,并在数据库中搜索一个名为“view_merchant”列“restaurant_name”的表,比较数据库中的名称请求,然后将其返回给应用程序 我添加了JS函数Php 从移动应用请求的数据库查询结果,php,api,hybrid-mobile-app,onsen-ui,Php,Api,Hybrid Mobile App,Onsen Ui,我正在将hybrid应用程序连接到web应用程序的API,以便在用户请求搜索后查询某些数据。我正在使用Onsen UI构建应用程序 服务器端的API代码应返回用户按其名称搜索的商户。结果应仅为1个商户(餐厅名称) 基本上,我从应用程序中发送一个参数名称“merchant”,API应该获取该参数,并在数据库中搜索一个名为“view_merchant”列“restaurant_name”的表,比较数据库中的名称请求,然后将其返回给应用程序 我添加了JS函数 var search_restaurant
var search_restaurant;
var search_cuisine;
var search_food;
$("#r").val( getStorage("search_restaurant") );
$("#c").val( getStorage("search_cuisine") );
$("#f").val( getStorage("search_food") );
function searchMerchantName()
{
var r = $('#r').val();
/*clear all storage*/
setStorage("search_restaurant",r);
removeStorage('merchant_id');
removeStorage('shipping_address');
removeStorage('merchant_id');
removeStorage('transaction_type');
removeStorage('merchant_logo');
removeStorage('order_total');
removeStorage('merchant_name');
removeStorage('total_w_tax');
removeStorage('currency_code');
removeStorage('paymet_desc');
removeStorage('order_id');
removeStorage('order_total_raw');
removeStorage('cart_currency_symbol');
removeStorage('paypal_card_fee');
if(r!=""){
var options = {
merchant:r,
closeMenu:true,
animation: 'slide'
};
menu.setMainPage('searchMerchants.html',options);
} else{
onsenAlert( getTrans('Restaurant Name is required','merchant_is_required') );
}
}
function searchCuisine()
{
var c = $('#c').val();
/*clear all storage*/
setStorage("search_cuisine",c);
removeStorage('merchant_id');
removeStorage('shipping_address');
removeStorage('merchant_id');
removeStorage('transaction_type');
removeStorage('merchant_logo');
removeStorage('order_total');
removeStorage('merchant_name');
removeStorage('total_w_tax');
removeStorage('currency_code');
removeStorage('paymet_desc');
removeStorage('order_id');
removeStorage('order_total_raw');
removeStorage('cart_currency_symbol');
removeStorage('paypal_card_fee');
if(c!=""){
var options = {
cuisine:c,
closeMenu:true,
animation: 'slide'
};
menu.setMainPage('searchCuisine.html',options);
} else{
onsenAlert( getTrans('Cuisine Type is required','cuisine_is_required') );
}
}
function searchFood()
{
var f = $('#f').val();
/*clear all storage*/
setStorage("search_food",f);
removeStorage('merchant_id');
removeStorage('shipping_address');
removeStorage('merchant_id');
removeStorage('transaction_type');
removeStorage('merchant_logo');
removeStorage('order_total');
removeStorage('merchant_name');
removeStorage('total_w_tax');
removeStorage('currency_code');
removeStorage('paymet_desc');
removeStorage('order_id');
removeStorage('order_total_raw');
removeStorage('cart_currency_symbol');
removeStorage('paypal_card_fee');
if(f!=""){
var options = {
foodname:f,
closeMenu:true,
animation: 'slide'
};
menu.setMainPage('searchFood.html',options);
} else{
onsenAlert( getTrans('Food Name is required','foodname_is_required') );
}
}
case "searchmerchant-page":
$("#search-text").html( getStorage("search_restaurant") );
callAjax("searchmerchant","merchant="+ getStorage("search_restaurant") );
break;
case "searchcuisine-page":
$("#search-text").html( getStorage("search_cuisine") );
callAjax("searchcuisine","cuisine="+ getStorage("search_cuisine") );
break;
case "searchfood-page":
$("#search-text").html( getStorage("search_food") );
callAjax("searchfood","foodname="+ getStorage("search_food") );
break;
case "page-home":
geoComplete();
search_address=getStorage("search_address");
if (typeof search_address === "undefined" || search_address==null || search_address=="" ) {
} else {
setTimeout('$("#s").val(search_address)', 1000);
}
translatePage();
$("#s").attr("placeholder", getTrans('Street Address,City,State','home_search_placeholder') );
//Added for Restaurant Name Search
search_restaurant=getStorage("search_restaurant");
if (typeof search_restaurant === "undefined" || search_restaurant==null || search_restaurant=="" ) {
} else {
setTimeout('$("#r").val(search_restaurant)', 1000);
}
translatePage();
$("#r").attr("placeholder", getTrans('Restaurant Name','restaurant_search_placeholder') );
//Added for Cuisine Type
search_cuisine=getStorage("search_cuisine");
if (typeof search_cuisine === "undefined" || search_cuisine==null || search_cuisine=="" ) {
} else {
setTimeout('$("#c").val(search_cuisine)', 1000);
}
translatePage();
$("#c").attr("placeholder", getTrans('Cuisine Type','cuisine_search_placeholder') );
//Added for Food Type
search_food=getStorage("search_food");
if (typeof search_food === "undefined" || search_food==null || search_food=="" ) {
} else {
setTimeout('$("#f").val(search_food)', 1000);
}
translatePage();
$("#f").attr("placeholder", getTrans('Food Name','food_search_placeholder') );
break;
function searchResultCallBack(address)
{
search_address=address;
}
function searchMerchantsCallBack(merchant)
{
search_restaurant=merchant;
}
function searchCuisineCallBack(cuisine)
{
search_cuisine=cuisine;
}
function searchFoodCallBack(foodname)
{
search_food=foodname;
}
您的SQL语句将是:
SELECT * FROM view_merchant WHERE lower(restaurant_name)=?
您需要
toLowerCase()
您传递的值$this->data['merchant']
,这样您就可以找到餐厅,而不必考虑大小写。唯一的问题是,如果存在同名的记录,则会返回多个记录 你需要什么帮助?您需要PHP页面和从JS调用该页面的示例吗?这不是针对Onsen的,所以我不清楚您需要什么帮助。@Munsterlander是的,它与Onsen无关,它是PHP,我将用JS函数更新问题以进行检查。我需要的是查询请求的数据并将其发回给用户。您希望数据如何返回JSON对象或字符串?我发布了SQL语句,这取决于您希望如何返回数据。JSON对象是最常见的。
SELECT * FROM view_merchant WHERE lower(restaurant_name)=?