radagast Posted June 15, 2012 Share Posted June 15, 2012 Hello I am hoping someone can PLEASSSSSSE help me I am trying to do the following php Script.. //Getting Information for firebird database from supplier/distributor try { $dbh = new PDO($dsndb, $userdb, $passdb); $sth = ("SELECT * from order WHERE account_number = 'abc123'"); foreach ($dbh->query($sth) as $row) // If I do print $row['order_number'].' - '. $row['customer_ref'] . '<br />'; returns all data.. { $row['order_number']; $row['customer_ref']; } } catch (PDOException $e) { echo 'You have the following error : ' . $e->getMessage() . "<br/>"; die(); } $on = $row['order_number']; $ref = $row['customer_ref']; // Need to update MYSQL Database but not sure how to create loop?????? mysql_connect("localhost", "user", "password") or die(mysql_error()); mysql_select_db("xoccoza_online") or die(mysql_error()); $sql = "UPDATE customer SET customer_ref = '$ref' WHERE order_number = '$on' and customer_ref IS NULL"; $result=mysql_query($sql) or die(mysql_error()); Any and all help will be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/ Share on other sites More sharing options...
trq Posted June 15, 2012 Share Posted June 15, 2012 Why are you executing a SELECT query in order to eventually do an UPDATE ? Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/#findComment-1354106 Share on other sites More sharing options...
radagast Posted June 15, 2012 Author Share Posted June 15, 2012 Hi Thorpe Thanks for responding. I tried many different scenarios to retrieve the data from the Firebird Database and the select seems to be the only one to work. If you have another method that will work please let me know. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/#findComment-1354111 Share on other sites More sharing options...
trq Posted June 15, 2012 Share Posted June 15, 2012 Ok, it wasn't clear from your post that the SELECT was selecting data from a different database. On to your issue. You already have the loop, you just need to move your mysql UPDATE code into it. Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/#findComment-1354113 Share on other sites More sharing options...
radagast Posted June 15, 2012 Author Share Posted June 15, 2012 Hi The problem is that it only updates the last row into the database. Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/#findComment-1354116 Share on other sites More sharing options...
trq Posted June 15, 2012 Share Posted June 15, 2012 Because (as I said) you need to move your UPDATE code so that it is within your loop. Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/#findComment-1354119 Share on other sites More sharing options...
radagast Posted June 15, 2012 Author Share Posted June 15, 2012 Hi Thorpe I really feel like a DUMBASS But a really happy DUMBASS Thanks for taking the time to help and have a GREAT weekend Quote Link to comment https://forums.phpfreaks.com/topic/264219-firebird-query-to-update-mysql-loop/#findComment-1354122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.