diff --git a/htdocs/commande/class/api_commande.class.php b/htdocs/commande/class/api_commande.class.php
index d6a2a3d0f82fa281b9a9e4464924f58c441c4bae..3a029bc0d000340377d38e2967fcae9b4913429c 100644
--- a/htdocs/commande/class/api_commande.class.php
+++ b/htdocs/commande/class/api_commande.class.php
@@ -160,6 +160,7 @@ class CommandeApi extends DolibarrApi
         
         if ($result)
         {
+        	$i=0;
             $num = $db->num_rows($result);
             while ($i < $num)
             {
diff --git a/htdocs/compta/facture/class/api_invoice.class.php b/htdocs/compta/facture/class/api_invoice.class.php
index 60098a38b9f7ed9c3627e0c505db051613850fc9..c64b5db89fe351ad35a255ef9f96a5cc72e00150 100644
--- a/htdocs/compta/facture/class/api_invoice.class.php
+++ b/htdocs/compta/facture/class/api_invoice.class.php
@@ -158,6 +158,7 @@ class InvoiceApi extends DolibarrApi
         $result = $db->query($sql);
         if ($result)
         {
+        	$i=0;
             $num = $db->num_rows($result);
             while ($i < $num)
             {
diff --git a/htdocs/product/class/api_product.class.php b/htdocs/product/class/api_product.class.php
index ae4ed46d30ec96220d254f3422fc86b1c26869d5..bf022260965d2f95a24445a6395c86a12ae5c833 100644
--- a/htdocs/product/class/api_product.class.php
+++ b/htdocs/product/class/api_product.class.php
@@ -147,6 +147,7 @@ class ProductApi extends DolibarrApi
         $result = $db->query($sql);
         if ($result)
         {
+        	$i=0;
             $num = $db->num_rows($result);
             while ($i < $num)
             {
@@ -232,6 +233,7 @@ class ProductApi extends DolibarrApi
         $result = $db->query($sql);
         if ($result)
         {
+        	$i=0;
             $num = $db->num_rows($result);
             while ($i < $num)
             {
diff --git a/htdocs/societe/class/api_contact.class.php b/htdocs/societe/class/api_contact.class.php
index 5144c000b4d634ba9aa2ba21bf0b574b89432a1a..884653e044d27b65244911138a8489cf80960f1d 100644
--- a/htdocs/societe/class/api_contact.class.php
+++ b/htdocs/societe/class/api_contact.class.php
@@ -114,6 +114,7 @@ class ContactApi extends DolibarrApi
 			$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
 		}
 
+		$search_sale = 0;
 		// If the internal user must only see his customers, force searching by him
 		if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid)
 			$search_sale = DolibarrApiAccess::$user->id;
@@ -164,7 +165,8 @@ class ContactApi extends DolibarrApi
 		$result = $db->query($sql);
 		if ($result)
 		{
-			$num = $db->num_rows($result);
+			$i = 0;
+		    $num = $db->num_rows($result);
 			while ($i < $num)
 			{
 				$obj = $db->fetch_object($result);
diff --git a/htdocs/societe/class/api_thirdparty.class.php b/htdocs/societe/class/api_thirdparty.class.php
index 507d95639e6c3da876b0a3088e3338ab82b6f620..42a2c2f0c22787c4aa8301709a01b5f841ac61fe 100644
--- a/htdocs/societe/class/api_thirdparty.class.php
+++ b/htdocs/societe/class/api_thirdparty.class.php
@@ -211,6 +211,7 @@ class ThirdpartyApi extends DolibarrApi
 		$result = $db->query($sql);
         if ($result)
         {
+			$i = 0;
             $num = $db->num_rows($result);
             while ($i < $num)
             {