0

我在从以下循环中获取所需的输出时遇到了一些问题。我想要的输出是一个如下所示的数组。

    Array
    (
        [0] => Array
            (
                [0] => 10013
                [1] => 8
                [2] => 2
                [3] => 6
                [4] => Array
                    (
                        [0] => Array
                            (
                                [0] => Jerk Chicken
                                [1] => Drink
                                [2] => 8
                                [3] => 2
                                [4] => 6
                            )

                    )

            )

        [1] => Array
            (
                [0] => 10107
                [1] => 28
                [2] => 28
                [3] => 0
                [4] => Array
                    (
                        [0] => Array
                            (
                                [0] => Konig Pilsener
                                [1] => Tobacco
                                [2] => 3.5
                                [3] => 3.5
                                [4] => 0
                            )

                    )

            )

        [2] => Array
            (
                [0] => 10259
                [1] => 18
                [2] => 18
                [3] => 0
                [4] => Array
                    (
                        [0] => Array
                            (
                                [0] => Trailer Grog
                                [1] => Tobacco
                                [2] => 7
                                [3] => 7
                                [4] => 0
                            )

                    )

            )

        [3] => Array
            (
                [0] => 10375
                [1] => 8
                [2] => 2
                [3] => 6
                [4] => Array
                    (
                        [0] => Array
                            (
                                [0] => Steak Sandwhich
                                [1] => Drink
                                [2] => 8
                                [3] => 2
                                [4] => 6
                            )

                    )

            )

    )

唯一的问题是它应该向我展示更多的价值,而不是我得到的那些。

我应该看到这个:http ://awesomescreenshot.com/0321af5cc4

谢谢你的帮助。我向你保证,我已经尝试了以下这么多变体,但都无济于事。

// all passing through correctly
global $actual; 
global $potentialarray;
global $compsarray;
global $CheckName;
}

unset($temparray);
unset($temparray2);

$i=0;
foreach ($CheckName as $value) {
$v=0;

$query8 = "SELECT * FROM Comps_Item_Name WHERE DOB="."'". $from_date."'"." AND CheckID=" . $value ." ORDER BY CheckID AND ITMNAME";
$result8 = mysql_query($query8) or die(mysql_error());
//$var= mysql_num_rows($result8);

    $row1[] = mysql_fetch_array($result8,MYSQL_ASSOC);


    //print_r($row1);
    //echo'<br>';
foreach ($row1 as $itemvalue){

    //Item Name
    $itemname = $itemvalue['ITMNAME'];
    $catname = $itemvalue['CatName'];   
    $saleprice = $itemvalue['SalePrice'];
    $discount1 = $itemvalue['Discount'];
    //Actual retail value of check
    $actual1= $itemvalue['SalePrice'] - $itemvalue['Discount']; 

    $temparray[$i][$v] = array($itemname, $catname, $saleprice, $discount1, $actual1);
    $v++;

}
echo '<pre>';
        print_r($temparray[$i]);
        echo '</pre>';


$temparray2[$i] = array($CheckName[$i], $potentialarray[$i], $compsarray[$i], $actual[$i], $temparray[$i]);
$i++;
unset($row1);
}

//  $DesiredOutput = array($CheckName, $potential[$i], $comps[$i], $actual[$i], array($itemname[$i][$v], $catnam[$i][$v], $saleprice[$i][$v], $discount1[$i][$v], $actual1[$i][$v]));
unset($itemname);
unset($catname);
unset($saleprice);
unset($discount1);
unset($actual1);

        echo '<pre>';
        print_r($temparray2);
        echo '</pre>';

有什么想法吗??干杯。

4

1 回答 1

0

这个问题似乎$row1[] = mysql_fetch_array($result8,MYSQL_ASSOC);只给了你第一行。尝试:

 $row1 = array();
 while($row = mysql_fetch_array($result8,MYSQL_ASSOC) ) {$row1[]=$row;}

也可以看看:

<?
error_reporting(E_ALL);
ini_set('error_reporting','on');
$CheckName=array('test1','test2');

for($i=0; $i<count($CheckName); $i++) 
{


/*$query8 = "SELECT * FROM Comps_Item_Name WHERE DOB="."'". $from_date."'"." AND CheckID=" . $value ." ORDER BY CheckID AND ITMNAME";
$result8 = mysql_query($query8) or die(mysql_error());
//$var= mysql_num_rows($result8);

    $row1[] = mysql_fetch_array($result8,MYSQL_ASSOC);*/

$row1 = array();  
$row1[] = array('ITMNAME'=>'cola','CatName'=>'drink'); 
$row1[] = array('ITMNAME'=>'beer','CatName'=>'drink');
$v=0;
foreach ($row1 as $itemvalue){

    //Item Name
    $itemname = $itemvalue['ITMNAME'];
    $catname = $itemvalue['CatName'];   


    $temparray[$i][$v] = array($itemname, $catname);
    $v++;

}
$temparray2[$i] = array($CheckName[$i], $temparray[$i]);

}


echo '<pre>';
print_r($temparray2);
echo '</pre>';
于 2013-05-18T14:15:58.747 回答