doubingjian2006 2015-11-08 02:52
浏览 26

在Jquery / Php / Mysql中过滤用户的自定义条件

im building a tool to send out emails to my user base. I want to create a dialog where users can create clauses to filter the users they want to send to. I.e.

"User who registered before 08/08/15" - which is pretty easy to do in a mysql query

But I want to let the user combine clauses to further filter users. I.e.

"User who registered before 08/08/15" and

"User who of group 2"

My question is, what is the most efficient way to get the right users? It is pretty easy to translate those two example conditions into a mysql query, but I dont know how I can keep the query flexible to basically take unlimmited clauses to work.

Sth. like

    $stmt = $mysqli->prepare("SELECT 
    id
    FROM users
    WHERE regDate > ?
    AND usergroup = ?
    ");

But regDate and usergroup are variable ofcourse depending on what the users clause says.

So again, the question is not how to translate a clause into a query but more how I insert a various amount of "where" clauses into a query in a dynamic way. Basically how to integrate a variable amount of "AND" clauses in a prepared statement. Hope you understand^^

  • 写回答

3条回答 默认 最新

  • dongmaopan5738 2015-11-08 02:57
    关注

    use MySQL str_to_date

     SELECT 
        id
        FROM users
        WHERE regDate > str_to_date('08/08/15','%d/%m/%y')
        AND usergroup = '2'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析
  • ¥15 生成的QRCode圖片加上下載按鈕
  • ¥15 板材切割优化算法,数学建模,python,lingo