From bb91523500571f2ac540c8850b82983c3c19c661 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Mon, 4 Aug 2003 14:20:42 +0000 Subject: [PATCH] bug fix --- htdocs/contrat/contrat.class.php | 38 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 8b7d42e8db6..76610a385a4 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -151,25 +151,33 @@ class Contrat if ($this->db->query($sql)) { $num = $this->db->num_rows(); - $i = 0; - - while ($i < $num) - { - $objp = $this->db->fetch_object($i); - $contrats[$i] = $objp->rowid; - $i++; - } - - $this->db->free(); - while (list($key, $value) = each ($contrats)) + if ($num > 0) { - $sql = "INSERT INTO llx_contrat (fk_product, fk_facture, fk_soc, fk_user_author)"; - $sql .= " VALUES ($value, $factureid, $socid, $user->id)"; - if (! $this->db->query($sql)) + $i = 0; + + while ($i < $num) { - print $this->db->error(); + $objp = $this->db->fetch_object($i); + $contrats[$i] = $objp->rowid; + $i++; } + + $this->db->free(); + + while (list($key, $value) = each ($contrats)) + { + $sql = "INSERT INTO llx_contrat (fk_product, fk_facture, fk_soc, fk_user_author)"; + $sql .= " VALUES ($value, $factureid, $socid, $user->id)"; + if (! $this->db->query($sql)) + { + print $this->db->error(); + } + } + } + else + { + $this->db->free(); } } else