Jump to content

Recommended Posts

One way to do it:

 

<?php
// sql connection above

$sql = "SELECT * FROM tbl_name ORDER BY name";
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res)) {
    if ($row['name'] == $oldName)
        continue;

    $delSQL = "DELETE FROM tbl_name WHERE id = " . $row['id'];
    mysql_query($delSQL);

    $newSQL = "INSERT INTO tbl_name (col1, col2, col3) VALUES ('" . $row['id'] . "', '" . $row['name'] . "', '" . $row['happy'] . "')";
    mysql_query($newSQL);
    echo $newSQL;
    $oldName = $row['name'];
}
?>

 

One word of warning, I would do a run through it with just the insert part and make sure the query is getting formatted correctly. I would also back up the current table data, just incase everything gets deleted and nothing gets re-populated.

 

Replace $row['name'] with an identifier of how you can if it is a duplicate.

 

But as a stated above, backing up your data is a must as this could delete all your rows etc and then your SOL.

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.