I'm trying to write a PHP script right now that
- uses a unique primary ID to search for a specific record in a database.
- It then should search a table for records that match certain fields of the first record(for example, find all entries with a name and date that is the same as "record one")
- it should then copy all entries that match into a new table.
Right now I have it only grabs one matching entry and then stops. How can I format this to copy over all entries?
$query = sprintf("SELECT name, date FROM original_table
WHERE id='%s'",
mysql_real_escape_string($id));
$result = mysql_query($query);
$row=mysql_fetch_array($result);
//find and copy all matching entries
$query = sprintf("INSERT into second_table(all fields)
SELECT all fields FROM original_table WHERE name='%s' AND date='%s'")
any suggestions as to what I can do to accomplish this?
In SQL, the query that you want is:
Do you want to exclude the original key? If so, include "and rec.key <> ot.key".