grissom Posted March 31, 2009 Share Posted March 31, 2009 Hi all I'm putting together a little synchronisation routine to transfer some stuff from one table (on localhost) up to a table on the server. First job I did is to pull the info off the table on localhost like this : $localheader_stuff = mysql_query("SELECT * FROM audit_header"); $ii = 0; while($localheader_row = mysql_fetch_array($localheader_stuff)) $localheader_line[$ii++] = $localheader_row; This has now pulled the data out of the local table and stored it in a series of arrays which I can access (and I have tested using 'echo') by specifying 2 dimensions eg echo $localheader_line[0]['user']; // to get the user field from the first record. So far so good ! Now to INSERT it into the server table. I connect up and go through each line of data at a time like this : for ($kk =0; $kk < $ii; $kk++) { // $ii is the number of lines plus one (see bit of code above) $success = mysql_query("INSERT INTO audit_header (user, zone) VALUES ('$localheader_line[$kk][user]', '$localheader_line[$kk][zone]')"); } But it's not working !! Somewhere I think I've got myself in a twist with some inverted commas or brackets but cannot work out how. help please ! many thanks !! Quote Link to comment https://forums.phpfreaks.com/topic/151906-inserting-into-mysql-table/ Share on other sites More sharing options...
grissom Posted March 31, 2009 Author Share Posted March 31, 2009 So far I've got round it by concatenating a string made up of the bits like $query = "INSERT INTO audit_header (user, zone) VALUES ('" . $localheader_line[$kk]['user']. "', '" . $localheader_line[$kk] . "', )" .. // etc etc and then running $success = mysql_query($query); If anyone else has any better ideas, please let me know, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/151906-inserting-into-mysql-table/#findComment-797768 Share on other sites More sharing options...
fenway Posted April 2, 2009 Share Posted April 2, 2009 Well, a multi-valued insert would be faster, but that's up to you. Quote Link to comment https://forums.phpfreaks.com/topic/151906-inserting-into-mysql-table/#findComment-799321 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.