Jump to content

Replace Into Help


waverider

Recommended Posts

http://dev.mysql.com/doc/refman/5.0/en/replace.htmlWhat does your schema look like? The Replace is not a standard sql method and has some requirements that are schema dependent, like it needs to apply on an indexed value.Can you use an Insert instead? Read the manual link above.
Link to comment
Share on other sites

Yes I have been referenced to this site before. I am trying to delete an entry from a table and insert one thing from that table into another. I was told that the REPLACE INTO is what I should look into. I dont know what the tables have to have incommon.Here is my table structure:

CREATE TABLE `comments` (  `comment_ID` bigint(20) unsigned NOT NULL auto_increment,  `comment_post_ID` bigint(20) unsigned NOT NULL default '0',  `comment_author` tinytext NOT NULL,  `comment_author_email` varchar(100) NOT NULL default '',  `comment_author_IP` varchar(100) NOT NULL default '',  `comment_date` datetime NOT NULL default '0000-00-00 00:00:00',  `comment_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',  `comment_content` text NOT NULL,  `comment_approved` enum('Yes','No') NOT NULL default 'No',  `comment_agent` varchar(255) NOT NULL default '',  PRIMARY KEY  (`comment_ID`),  KEY `comment_approved` (`comment_approved`),  KEY `comment_post_ID` (`comment_post_ID`),  KEY `comment_approved_date_gmt` (`comment_approved`,`comment_date_gmt`),  KEY `comment_date_gmt` (`comment_date_gmt`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15;CREATE TABLE `banned_comments` (  `id` int(55) NOT NULL auto_increment,  `usr_ip` char(15) NOT NULL default '0',  PRIMARY KEY  (`id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

Link to comment
Share on other sites

I am trying to delete an entry from a table and insert one thing from that table into another.
That will be more than one query, REPLACE INTO operates on a single table. You can use an INSERT..SELECT query to insert a record from one table into another table, and then delete the original.
Link to comment
Share on other sites

That will be more than one query, REPLACE INTO operates on a single table. You can use an INSERT..SELECT query to insert a record from one table into another table, and then delete the original.
That is proboly where my problem is. So would I do the delete query after I do the insert? So:
$sql = "INSERT $ip INTO ban_comm";if(mysql_query($sql)) {$sql = "DELETE FROM comments WHERE comment_ID = '$comment_id'";mysql_query($sql);}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...