Link to home
Start Free TrialLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php xml loop

Code I am interested in:

The following code in the attached file is supposed to add the "orderdesc2" val;ues into sequential database columns named it2, it3 and it4   using the $i value in a loop. The first two values ($name and $orderdesc) are added but the values assigned to the $i variable do not bget anything

-------------------------------

//prepare the query
$stmt = $dbh->prepare("INSERT INTO orders(custName, orderDetails, it$i) VALUES (:name, :orderdesc, :orderdesc2)");

//bind the named parameter to a PHP variable (called $name and $orderdesc etc )
$stmt->bindParam('name', $name);
$stmt->bindParam('orderdesc', $orderdesc);
$stmt->bindParam('orderdesc2', $orderdesc2);

$name = (string)$obj->header->manifest->document->name;
$orderdesc = (string)$obj->body->ORDER->ORDERHEAD->ORDERDESC;


//loop through the orderline to get each product description
for ($i=2; $i <= 4; $i++) {
      $orderdesc2 = $orderline->PRODUCT->DESCRIPTION;      }
      //execute the query
      $stmt->execute();
Purchase-Order-FI2-4098098-edit.xml
xmlimport-form-loop.php
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doctorbill

ASKER

What I want is the following:
1 row of date
CustName column has the $name value
OrderDetails column has the $orderdesc value
it$i (it2, it3, it4) columns have the values from the $orderdesc2 as a sequence

So, there will be 1 row and 5 columns added
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I quite agree but the database I am working with is set like it is
Is there a way of doing what I am trying to do with the $i loop ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes please - so I can see the mechanism
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you put that in the code please

Yes - I will take on board what you say re. the database and start using 2 tables
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I see what you mean about complications arising !!

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Exactly what I will be doing with it
Thanks very much all
Solution