Hi,

I am using the following code to get an updated version of
my main data table. The main data table contains all the history
whereas the daily update only contains one days worth.

To prevent the comparison with the whoşe of the main
table, I have used the WHILE statement.

I have a feeling that this is not going to work.
But I am not sure how to do this.


This is the code:

PHP Code:
$sql "SELECT cb_update.*, cb_main.* FROM cb_update LEFT JOIN cb_main ON cb_update.id=cb_main .id WHERE cb_update.day_no = '$dayno' ORDER BY cb_update.id";

$result mysql_query($sql)
    or die(
"could not JOIN cb_last AND cb_prev"mysql_error()); 
The two tables have identical structure:
day_no, id, title, desc, data1, data2, ... data18

In the cb_main table, I have all the history so data will look like:

day_no, id, title, desc, data1, data2, ... data18
4, HERB34, the title, and description, 56, 549.34, ...
4, CFR89X, another title, descrip, 892.56, 567.21 ...
3, HERB34, the title, and description, 33, 589.44, ...
3, CFR89X, another title, descrip, 498.22, 61.21 ...
2, HERB34, the title, and description, 112, 444.27, ...
2, CFR89X, another title, descrip, 989.43, 22.00, 21.88...

Whereas the cb_update only contains one day eg

day_no, id, title, desc, data1, data2, ... data18
5, HERB34, the title, and description, 56, 549.34, ...
5, CFR89X, another title, descrip, 203.89, 143.56 ...
5, GGGG55,new title, new product. 0.00, 12.74 ...

As you can see there is a new product GGGG55
in day 5 so I need to find that record.

Also the record for CFR89X has got new data, so
I need to record that row into the cb_main table.

The lines that are not changed do not need to be added.

This is a bit hard to get my head around

I think that I might have to step through the entire update table and
compare each data record with the last day on the main table.

Probably there is no "batch" command to do this operation ??
Unless someones knows more ??

Would appreciate any suggestions.