PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
MYSQL_QUERY( "insert into $table1 SELECT * FROM $table2 where 1 ");
There are 24 fields in each table, my problem is if a reference number ( ie. R12121 ) exists in table1 i want it to update and not add new record, how can this be done?
a) Modify the SELECT to do an outer JOIN against the destination table and only keep the null rows
b) Add a WHERE where the field is NOT IN the other table (don't do this if the tables are large)
c) REPLACE INTO
Put it this way: can you write a SELECT query that retrieves exactly what you want to insert? Start with the $table2 and LEFT JOIN $table1 on a matching reference number. Since it's a LEFT join if there's no matching row in $table1 then you'll get back a bunch of NULLs. Then limit the query to only those rows.
Thanks for your reply requinix but sorry im not too good with mysql ( table1 is called portal and table 2 is called portal2 and field for the match is called reference )
1. "matching reference numbers". You have two tables, both with a reference number column. What do you write to check if the values match?
2. "primary key". What is the primary key of the table?