Hi, I'm trying to shift old records into another table (Archive), but I'm not really sure how to go about it. I do have it sort of working but I can foresee problems with it and it just doesn't look good / efficient. Here's what I have:
There's only one row to get, as it's done by IDs, so it gets the row as an array, then I chop it up, escape characters like ' which terminate the query string, then put it back together and then do that big ugly statement, putting each row in the correct value slot.PHP Code:$archiveq = mysql_query("SELECT * FROM enquiries WHERE `id` = '$id'");
$row = mysql_fetch_row($archiveq);
$rowstring = implode($row, ",");
$rowstring = mysql_real_escape_string($rowstring);
$row = explode(",", $rowstring);
$updatearchive = mysql_query("INSERT INTO archive (id, phone_no, boat_type, name, address, start_date, finish_date, deposit, payment_received, description, email) VALUES ('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[4]', '$row[5]', '$row[6]', '$row[7]', '$row[8]', '$row[9]', '$row[10]')");
if(!$updatearchive)
die('Error inserting into archive: ' . mysql_error());
The problem with this is that if a field has a comma within it, it breaks it up, so another value is added to the array.
Anyone got any ideas on improving this? I was thinking that INNER JOIN would come into it somewhere but I'm not so great with databases.
Cheers.



Reply With Quote

Bookmarks