Ninjakreborn Posted October 4, 2007 Share Posted October 4, 2007 <?php foreach($customers AS $key => $value) { $fpdf->Cell(30, 10, $key, 1, 0, 'C'); $fpdf->Cell(30, 10, $value['forecast'], 1, 0, 'C'); $fpdf->Cell(30, 10, $value['actual'], 1, 0, 'C'); $fpdf->Cell(30, 10, $value['gam'], 1, 0, 'C'); $fpdf->Cell(30, 10, $value['actual'] + $value['gam'] - $value['forecast'], 1, 1, 'C'); foreach($value['products'] AS $key2 => $value2) { $fpdf->Cell(30, 10, '', 1, 0, 'C'); $fpdf->Cell(30, 10, $key2, 1, 0, 'C'); $fpdf->Cell(30, 10, $value2['forecast'], 1, 0, 'C'); $fpdf->Cell(30, 10, $value2['actual'], 1, 0, 'C'); $fpdf->Cell(30, 10, $value2['gam'], 1, 0, 'C'); $fpdf->Cell(30, 10, $value2['actual'] + $value2['gam'] - $value2['forecast'], 1, 1, 'C'); } } ?> Why no matter how I do this I always get, a Warning: Cannot use a scalar value as an array in D:\xampp\htdocs\rolfdev\app\views\reconcile\area_customer_pdf.thtml on line 30 Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\rolfdev\app\views\reconcile\area_customer_pdf.thtml on line 30 [/quote error. There is an array inside $value['products'] but it returns that for some reason. Any advice? Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 Do this and post the output. <?php echo "<pre>"; print_r($customers); echo "</pre>"; ?> Quote Link to comment Share on other sites More sharing options...
marcus Posted October 4, 2007 Share Posted October 4, 2007 Try setting $value = array(); then calling the parameters inside it. Also, does $customers exist? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 4, 2007 Author Share Posted October 4, 2007 @ MmmVomit I can't show customer's "data" because it's a private project. The original array is called products. I have split it into 2 arrays products['customers'] is going into customers and the other part somewhere else. I am focusing on customers. Which is now the $customers array. Inside it are some values, and one array. Which is products. customers[value] customers[value2] customers[value3] customers[products] -> array inside that array are product id -> values. For each one. Note: @mgallforever I tried that, as well as unsetting each one at the end both. No luck. Quote Link to comment Share on other sites More sharing options...
marcus Posted October 4, 2007 Share Posted October 4, 2007 Is $customers alone set to an array? if(is_array($customers)){ echo "array"; }else { echo "not an array"; } Quote Link to comment Share on other sites More sharing options...
MmmVomit Posted October 4, 2007 Share Posted October 4, 2007 @ MmmVomit I can't show customer's "data" because it's a private project. I'm more interested in the structure of the variable. Replace all the actual data with asterisks if you need to. Unless the array is to large to do that cut and paste by hand, of course. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 4, 2007 Author Share Posted October 4, 2007 Yes, customers is the array customers. It works fine,without the second foreach. $customers['products'] howeverwhich I am trying to access in the second foreach is, but funny. It's $customers['customerid']['products'] is an array of product id's Like $customers['customerid']['products -> array ( $prod_id = array ( value = whatever value2 = whatever again value3 = something else ) ) That's basically it. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 4, 2007 Share Posted October 4, 2007 It's saying you can't do this ie use a var as a scalar value then try to use it as an array <?php $customers = 0; $customers[0] = 'fred'; ?> [pre] --> Warning: Cannot use a scalar value as an array in test.php on line 4 [/pre] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 4, 2007 Author Share Posted October 4, 2007 Ok, I tried that just now. I don't understand exactly what this error is. I know, btu I don't know how to fix it. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 4, 2007 Share Posted October 4, 2007 Ok, I tried that just now. I don't understand exactly what this error is. I know, btu I don't know how to fix it. the answer is don't use a scalar as an array. <?php $customers = 0; // Here $customers is a scalar variable with value 0. // DO NOT TRY TO ASSIGN VALUES TO IT LIKE AN ARRAY $customers[0] = 'fred'; // Here we're trying to assign a value to $customer as if it's an array, but it's a scalar. // DON'T DO THAT! ?> Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 5, 2007 Author Share Posted October 5, 2007 I figured it out. It was strange.... thanks for the feedback. Quote Link to comment Share on other sites More sharing options...
marcus Posted October 5, 2007 Share Posted October 5, 2007 What ended up being the problem? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.