Jump to content


Photo

Invalid argument supplied for foreach


  • Please log in to reply
4 replies to this topic

#1 Yohanne

Yohanne

    Advanced Member

  • Members
  • PipPipPip
  • 185 posts

Posted 04 July 2013 - 11:07 PM

hello coders.

 

what is the possible reason why i get this warning:   Invalid argument supplied for foreach() in

 and i have no idea behind this code, but i know there is someone else can read this and understand behind the logic. 

$orders = Order::getOrdersWithInformations(10);
$i = 0;
foreach($orders AS $order)
{
      $currency = Currency::getCurrency((int)$order['id_currency']);
	echo '
	<tr'.($i % 2 ? ' id="order_line1"' : '').'>
	<td class="order_td_first order_id">'.(int)$order['id_order'].'</td>
	<td class="order_customer">'.Tools::htmlentitiesUTF8($order['firstname']).' '.Tools::htmlentitiesUTF8($order['lastname']).'</td>
	<td class="order_status">'.Tools::htmlentitiesUTF8($order['state_name']).'</td>
	<td class="order_total">'.Tools::displayPrice((float)$order['total_paid'], $currency).'</td>
	<td class="order_action">
	<a href="index.php?tab=AdminOrders&id_order='.(int)$order['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'" title="'.$this->l('Details').'"><img src="../img/admin/details.gif" alt="'.$this->l('See').'" /></a>
			</td>
			</tr>
				';
			$i++;
		}


#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,236 posts
  • LocationWA

Posted 05 July 2013 - 01:54 AM

Because $orders is not an array (or other iterable object). Check that getOrdersWithInformation().

#3 applebiz89

applebiz89

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts

Posted 09 July 2013 - 11:19 AM

If your not sure of the output of the result for getOrdersWithInformation() - wrap a conditional statement around your foreach, checking that the result of getOrdersWithInformation() is an array, so the foreach loop isn't instantiated and causing any errors if the result is false...


"Don't just stare at it, eat it!" - Adopting Patrick Bateman's philosophy in back-end development, don't just stare at a problem - tackle it and do something about!

 

Personal Website

 

@applebiz89


#4 web_craftsman

web_craftsman

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts
  • LocationUkraine

Posted 11 July 2013 - 01:47 AM

Show us the output var_dump function  will  print:

$orders = ...
var_dump($orders);


#5 Maq

Maq

    Advanced Member

  • Moderators
  • 9,362 posts
  • LocationPennsylvania, USA

Posted 11 July 2013 - 05:42 PM

Post your getOrdersWithInformations() method. Is there a reason it's static?


tjmothy

ini_set ("display_errors", "1");
error_reporting(E_ALL);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com