PHP or SQL to do this?

From: Date: Wed, 24 Feb 2010 05:46:38 +0000
Subject: PHP or SQL to do this?
Groups: php.general 
Request: Send a blank email to php-general+get-302330@lists.php.net to get a copy of this message
I'm not sure if I need to write a PHP for-loop to do this, or if it can all be done in one SQL statement? Basically, I want to copy all the barcodes from one table and put them into another table, but only if the barcode in the first table > 0, and only if the wineid's match from table to table. Steps individually are something like this: 1) First, I get all the records from the "wine" table that have barcodes, like this: SELECT * FROM wine WHERE barcode2 > 0 The fields I need are "barcode2", and "wineid" 2) Next, I need to match all the wineid's from this "wine" table with the wine id's from the "usersdata" table. Both fields in both tables are called "wineid". 3) Then, if the wineid's match, I need to copy the "barcode2" value from the wine table and put it into the field "custombarcode" in the "usersdata" table. I'm tempted to write a PHP script which does a while-loop through all the records returned from the wine table and do the matching with the usersdata table, but I wouldn't be surprised if there's some sort of table-join-type query that can do all this in one step.

« previous php.general (#302330) next »