doctorbill
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('orderdes c', $orderdesc);
$stmt->bindParam('orderdes c2', $orderdesc2);
$name = (string)$obj->header->mani fest->docu ment->name ;
$orderdesc = (string)$obj->body->ORDER- >ORDERHEAD ->ORDERDES C;
//loop through the orderline to get each product description
for ($i=2; $i <= 4; $i++) {
$orderdesc2 = $orderline->PRODUCT->DESCR IPTION; }
//execute the query
$stmt->execute();
Purchase-Order-FI2-4098098-edit.xml
xmlimport-form-loop.php
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('orderdes
$stmt->bindParam('orderdes
$name = (string)$obj->header->mani
$orderdesc = (string)$obj->body->ORDER-
//loop through the orderline to get each product description
for ($i=2; $i <= 4; $i++) {
$orderdesc2 = $orderline->PRODUCT->DESCR
//execute the query
$stmt->execute();
Purchase-Order-FI2-4098098-edit.xml
xmlimport-form-loop.php
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 ?
Is there a way of doing what I am trying to do with the $i loop ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes please - so I can see the mechanism
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Yes - I will take on board what you say re. the database and start using 2 tables
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I see what you mean about complications arising !!
Thanks
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Exactly what I will be doing with it
Thanks very much all
Thanks very much all
ASKER
Solution
ASKER
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