Forum Moderators: coopster

Message Too Old, No Replies

Fetch_array, multiple rows

         

briesm

7:49 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Hey, I'm using SOAP to call a function on my online server from a remote computer. It does not allow me to pass the entire $result that I get from my query. I have been able to pass an array variable that I got from a mysql_fetch_array but this is only the first row and my query is meant to return all rows. SQLDump is not appropriate for this because i'm not looking to backup data, but only insert rows from one mysql to another...

The Question:
How can I pass along and access all rows from my query and then insert them into my local mysql database. I read that maybe a multi-dimensional array that contained all rows from my query could maybe do it but i'm a little lost. Any suggestions?

briesm

9:05 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



Actually, I read another post that covered multi-dimensional arrays and I used a format like $array[0]['ordernumber'] for the first row, [1] and so on for next rows....I've printed them out and saw that all values are passed. Now, my problem is that they are not properly inserting into my sql database.

Here's my code to add to the database:

for ($i=0; array_key_exists($i, $line); $i++) {

$result = MYSQL_QUERY("INSERT INTO customerMaster SET
order_Num= '$line[$i]['order_Num']',
date= '$line[$i]['date']',
territory= '$line[$i]['territory']',
salesRep= '$line[$i]['salesRep']',
repEmail= '$line[$i]['repEmail']',
facility= '$line[$i]['facility']',
address= '$line[$i]['address']',
contact1= '$line[$i]['contact1']',
otherDiscounting='$line[$i]['otherDiscounting']'");
}

Any ideas? Line is an associative array and i did see that it does in fact pass along all the right entries.

mcibor

10:10 pm on Jun 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You want to copy some rows from one table to another? Use INSERT SELECT function

There are some mistakes in your code - you cannot write $a = "$b['1']['bla']some text here". Moreover there's no structure INSERT.... SET. There's only INSERT INTO ... VALUES or UPDATE... SET. I'll write as if you wanted to insert new:

This should work:

for ($i=0; array_key_exists($i, $line); $i++) {

$result = mysql_query("INSERT INTO customerMaster(order_Num, date, territory, salesRep, repEmail, facility, address, contact1, otherDiscounting) VALUES ('".$line[$i]['order_Num]."', '".$line[$i]['date']."', '".$line[$i]['territory']".', '".$line[$i]['salesRep']."', '".$line[$i]['repEmail']."', '".$line[$i]['facility']."', '".$line[$i]['address']."', '".$line[$i]['contact1']."', '".$line[$i]['otherDiscounting']."'");
}

Best regards
Michal Cibor