Jump to content

PHP script, selecting and inserting into mysql without duplicates


thenorman138
Go to solution Solved by ginerjm,

Recommended Posts

This actually makes the most sense. The only thing is I'm not sure of is the 'values' part of the insert. Since I've already retrieved everything in the first select statement, I would basically need to insert the values based on index or column name and loop it. What would be the syntax there, as opposed to explicit values like you showed?

Depends on exactly how you retrieve them in the query, but you'd likely build it something like

 

$insert[] = "({$row['sessionid']}, {$row['name']}, {$row['number']})";

 

within the loop, for each row, then implode() that $insert array with a comma value when you're ready to tack it on to the end of the actual query.

 

$query = "INSERT INTO proddb.tablename (sessionid, name, phone, ...) VALUES " . implode(',', $insert);

 

Include your actual column names and make sure the number of columns listed matches the number of values in each VALUE () element and all that jazz. This is just an example.

 

-John

Edited by Sepodati
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.