Jump to content

inserting into mysql table


grissom

Recommended Posts

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 !!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.