I'm currently using jquery's ajax feature or whatever they call it. To load data from mysql database. Its working fine, but one of the built in features of this one is to load all the data which is on the database when you press on backspace and there's no character left on the text box.

我目前正在使用jquery的ajax功能或他们称之为的任何功能。从mysql数据库加载数据。它的工作正常,但这个的内置功能之一是当你按退格键时加载数据库上的所有数据,文本框上没有任何字符。

Here's my query:

这是我的查询:

SELECT * FROM prod_table WHERE QTYHAND>0 AND PRODUCT LIKE '$prod%' OR P_DESC LIKE '$desc%' OR CATEGORY LIKE '$cat%'

As you can see I only want to load the products which has greater than 0 quantity on hand.

如您所见,我只想加载手头数量大于0的产品。

I'm using this code to communicate to the php file which has the query on it:

我正在使用此代码与php文件进行通信,该文件包含查询:

$('#inp').keyup(function(){


                var inpval=$('#inp').val();

            $.ajax({
                type: 'POST',
                data: ({p : inpval}),
          url: 'querys.php',
          success: function(data) {
            $('.result').html(data);

          }





        });

    });

Is it possible to also filter the data that it outputs so that when I press on backspace and there's no character left. The only products that's going to display are those with greater than 0 quantity?

是否也可以过滤它输出的数据,这样当我按下退格键并且没有剩下的字符时。唯一可以展示的产品是数量大于0的产品?

1 个解决方案

#1


2

I think all you have to do is to change your query to:

我认为您所要做的就是将查询更改为:

SELECT * 
FROM prod_table 
WHERE QTYHAND>0 
AND (
    PRODUCT LIKE '$prod%' 
    OR P_DESC LIKE '$desc%' 
    OR CATEGORY LIKE '$cat%'
)

Not 100% sure if it is the same in SQL, but most often, AND has precedence over OR. So your original query would read like:

不是100%确定它在SQL中是否相同,但最常见的是,AND优先于OR。因此,您的原始查询将如下所示:

WHERE (... AND ...) OR ... OR ...

Now, if you have an empty string, then "something LIKE '%'" will always match and only one OR has to match to include the record in the result set.

现在,如果你有一个空字符串,那么“LIKE'%'”将始终匹配,并且只有一个OR必须匹配才能在结果集中包含记录。

更多相关文章

  1. Yii - 加载ajax表单元素的用户端验证
  2. 用JQuery写的一个简单的验证码功能
  3. jQuery使用微调器加载整个HTML页面
  4. 基于jQuery实现页面搜索功能----项目实战
  5. jquery Loading图片延迟加载特效
  6. 关于INPUT的autocomplete="off" 属性(浏览器表单默认的记忆功能)
  7. 使用jQuery和AJAX从JSON文件加载数据
  8. IOS学习之WebView加载本地HTML代码或网络资源
  9. HTML5实现图片预览功能

随机推荐

  1. [置顶] android Properties的使用
  2. android apk包签名和align
  3. 自定义全屏Dialog
  4. Android再次按back键退出
  5. 使一个button无效时变灰
  6. Android开发整理
  7. 在gradle中配置umeng多渠道以及不同的ume
  8. Android 获取View高度宽度
  9. WebViewJavascriptBridge实现js与android
  10. Android常用框架地址