Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:显示来自数组的数据_Php_Mysql_Arrays - Fatal编程技术网

PHP:显示来自数组的数据

PHP:显示来自数组的数据,php,mysql,arrays,Php,Mysql,Arrays,我正在做一个程序,遇到了一些恼人的问题。我试图显示数组中的数据。我从我设置的另一个数组中复制了格式,它工作得非常完美。唯一的区别是我收集了更多的数据 调用函数: $data1 = display_orders($_SESSION['user_id'], $limit, 'fName', 'lName', 'VendorName', 'DateRequested', 'Shipping', 'VendorNumber', 'VendorFax', 'VendorAddress', 'Ve

我正在做一个程序,遇到了一些恼人的问题。我试图显示数组中的数据。我从我设置的另一个数组中复制了格式,它工作得非常完美。唯一的区别是我收集了更多的数据

调用函数:

$data1 = display_orders($_SESSION['user_id'], $limit, 'fName', 'lName', 'VendorName',      'DateRequested', 'Shipping', 'VendorNumber', 'VendorFax', 'VendorAddress', 'VendorCity', 'VendorState', 'VendorZip', 'EquipmentConsumable', 'GasType', 'GasLocation', 'UNMTag', 'EquipmentLocation', 'index', 'totalcost', 'Approved', 'Shipped');
函数本身

<?php
function display_orders($user_id, $limit)
{
    $data = array();
    $user_id = (int)$user_id;
    $limit = (int)$limit;

        $func_num_args = func_num_args();
        $func_get_args = func_get_args();

//  print_r($func_get_args);
                if ($func_num_args > 1)
                        {
                                unset($func_get_args[0]);
                unset($func_get_args[1]);


                                $fields = '`' . implode('`, `', $func_get_args) . '`';

                for($x = 0; $x < $limit; $x++)
                {   

                $data[] = mysql_fetch_assoc(mysql_query("SELECT $fields  FROM  `users` ,  `vendor` WHERE $user_id = users.id AND $user_id = vendor.user_id ORDER BY vendor.DateRequested DESC"));
                }
                return $data;
            }

}

?>
我没有输出

如果我这样做:

print_r ($data1);
我得到输出

数组([0]=>Array([fName]=>admin[lName]=>test[VendorName]=>Newegg[DateRequested]=>2013-09-19[Shipping]=>Standard[VendorNumber]=>NA[VendorFax]=>NA[VendorCity]=>NA[VendorState]=>NA[VendorZip]=>00000[Equipment耗材]=>Equipment[GasType]=>GasLocation]=>UNMTag=>0[设备位置]=>计算机实验室[索引]=>0[总成本]=>39.99[批准]=>0[已装运]=>0)

但是如果我尝试添加一个字段名,没有数据


如有任何帮助,我将不胜感激!

如您所见,
$data1
Array([0]=>Array(…)
,因此您需要致电

echo $data1[0]['VendorName'];
这是因为您将数据分配为
$data[]=mysql\u fetch\u assoc(…)


我建议在使用print\r时,您首先回显
,因为它将帮助您更容易地查看阵列的真实结构。在这种情况下,VendorName的位置比您回显的位置深一层。

您忘记了索引
[0]

echo $data1[0]['VendorName'];

echo$data1[0]['VendorName']];
或者如果输出到浏览器,只需“查看源代码”。使用
echo',打印($data1),“”;
对数组进行格式化输出。谢谢!这是一个愚蠢的错误!
echo $data1[0]['VendorName'];
echo $data1[0]['VendorName'];