简体   繁体   English

MySQL查询,在哪里和日期之间? 和?

[英]MySQL Query, WHERE IN, AND date BETWEEN ? AND?

My query works up until I try to limit it a bit more by adding a date range where clientid in with the implode function works well. 我的查询工作直到我尝试通过添加一个日期范围来限制它,在该日期范围中,带有implode函数的clientid效果很好。 But I can't figure out how to add the date range limit in here. 但我不知道如何在此处添加日期范围限制。

Every time I add 每次我添加

STR_TO_DATE(date, \'%m/%d/%Y\') BETWEEN ? AND ?

To

SELECT invid, packid, clientid, date_range_start, date_range_end, value 
FROM inv_packs 
WHERE clientid IN (' . implode(',', $in) . ')

It breaks 坏了

I've been roaming around trying to find these two being used together as an example, and have been going back and forth trying different things to get this to work but no luck, any help is greatly appreciated. 我一直在漫游,试图找到将两者一起使用作为示例,并且一直在来回尝试各种不同的方法以使其正常工作,但是没有运气,非常感谢您的帮助。

Here's the full simplified code for the query: 这是查询的完整简化代码:

$l = count($uniqueIds);
$types = 'ss';
$types .= str_repeat('i', $l);

$num_of_invoices = count($invoice_table_data);
$inv_pack_count = 0;

$in = array_fill(0, count($uniqueIds), '?');

$query_inv_packs_for_date_range = 'SELECT invid, packid, clientid, date_range_start, date_range_end, value FROM inv_packs WHERE STR_TO_DATE(date, \'%m/%d/%Y\') BETWEEN ? AND ? AND clientid IN (' . implode(',', $in) . ')';

if($stmt2 = mysqli_prepare($connection, $query_inv_packs_for_date_range)){
      mysqli_stmt_bind_param($stmt2, $types, $filter_min_date, $filter_max_date, ...$uniqueIds);
      mysqli_stmt_execute($stmt2);
      mysqli_stmt_bind_result($stmt2, $invoice_id, $pack_id, $client_id_from_inv_pack_table, $date_range_start, $date_range_end, $value);

      while(mysqli_stmt_fetch($stmt2)){
           $invoice_packs_table_data[$inv_pack_count]['date_range_start'] = $date_range_start;
           $inv_pack_count++;

           echo " " . $date_range_start;

       }
       print_r($invoice_packs_table_data);
       $stmt2->close();
}

simple variable error on my end, but the syntax for this MySQL query was correct. 简单的变量错误,但是此MySQL查询的语法正确。 Wish there was some emojis here to roll my eyes way back. 希望这里有一些表情符号可以让我回望过去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM