Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

PHP script to update a table in a database from a table in another database

I have to write a script in php to run with a cron job to update data in a column in a table in a database from the data in a column in a table in a separate database. I am updating the amount of inventory of a product so I must update the appropriate product using presumably the SKU number since that will be the only data both tables have in common. I am new to php and just started here on treehouse, but need to get this task done and finding google to be an over saturation of information and ultimately unproductive. Could someone please give me a lead on how to do so and break down how to code is working. THANKS IN ADVANCE FOR ALL HELP!!

1 Answer

Without having a lot more to go on. Perhaps read in the information from table 1 and stuff it into an array containing only the data you need to update the second table. Connect to table 2 and using your array, update the data in table 2. Maybe index your array using the related foreign key and you could easily loop through the array and issue an update query for every record encountered.

Thank you for your reply that makes a lot of sense.