简体   繁体   English

在php中创建多维数组

[英]create multi-dimensional array in php

I am having trouble trying to figure out how to populate a multi-dimensional array. 我在尝试弄清楚如何填充多维数组时遇到麻烦。 Let's say I have a table of transactions with various billing dates. 假设我有一张带有不同结算日期的交易表。 First I have an array that retrieves the following 'billed' dates: 首先,我有一个检索以下“开票”日期的数组:

Array
(
    [0] => Array
        (
            [BILLED] => 2011-11-18 00:00:00
        )

    [1] => Array
        (
            [BILLED] => 2011-11-22 00:00:00
        )

)

I also have the following query which is currently hard-coded to one of the two 'billed' dates shown above: 我还具有以下查询,该查询当前已硬编码为上面显示的两个“开票”日期之一:

$qryOrders = $this->db->query("
       SELECT tblOrders.* 
       FROM tblOrders 
       WHERE tbltc.BILLED = '2011-11-22'"); 
$data['Orders'] = $qryOrders->result_array();

I know that I can very easily determine the count of array items by using count($Orders); 我知道我可以使用count($ Orders)轻松确定数组项的数量; but how can I instead pass through each of the 'billed' dates of 2011-11-18 and 2011-11-22 to that I can determine the overall count, for both of the specified dates? 但是我该如何通过2011-11-18和2011-11-22的每个“开票”日期来确定两个指定日期的总计数?

I hope I've explained it clearly enough. 我希望我已经解释清楚了。 I am thinking that I probably need some kind of foreach loop and each time through the loop I could pass in the billed date, and keep track of a running total each time through the loop. 我在想,我可能需要某种foreach循环,并且每次通过循环时,我都可以传递计费日期,并跟踪每次循环中的运行总计。

Any ideas would be greatly appreciated. 任何想法将不胜感激。 Thanks, 谢谢,

// this is getting all results for a record
$sql = 
<<<sql
SELECT tblOrders.* 
FROM tblOrders 
WHERE tbltc.BILLED between '{$arr[0]}' and '{$arr[1]}'
sql;

// this is to get total count of matched record
// $sql = 'select count(*) from ..';

if you are using CI, you can easily using bind 如果您正在使用CI,则可以轻松使用bind

example:- 例:-

$sql = 'SELECT tblOrders.* FROM tblOrders WHERE tbltc.BILLED between ? AND ?';
$this->db->query($sql, array($arr[0], $arr[1]));

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

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