I have this code.
$db_update_syntax = array(
"INSERT INTO posts (SELECT NULL,'TEMP','".$data->cid."',title,img,redirect,redirect_full,site_name,description,longurl,shorturl,publishdate,publishtime,platform,post_type,youth,volunteers,biomed,img_idea,client,category,sme,approved,featured,announce,dynamic_content,trash,archive,NULL FROM posts WHERE cid='".$orig_cid."' AND trash != 1)",
"SET @subdomain = (SELECT SUBSTRING_INDEX(guid, '-', 1) FROM posts WHERE cid ='".$orig_cid."' limit 1)",
"SET @html = (SELECT LEFT(longurl, LENGTH(longurl) - LOCATE('/', REVERSE(longurl))+1) FROM posts WHERE cid ='".$orig_cid."' limit 1)",
"SET @postid = (SELECT id FROM posts WHERE cid ='".$orig_cid."' limit 1)",
"SET @newpostid = (SELECT id FROM posts WHERE cid ='".$data->cid."' limit 1)",
"UPDATE posts SET guid=CONCAT(@subdomain,'-',id) WHERE cid='".$data->cid."'",
"UPDATE posts SET longurl=CONCAT(@html,id,'.html') WHERE cid='".$data->cid."'",
"INSERT INTO platform_xrf (SELECT NULL,0,platformid FROM platform_xrf WHERE postid=@postid)",
"UPDATE platform_xrf SET postid=@newpostid WHERE postid=0"
);
I have three tables: post table, platform table and platform_xrf table.
The platforms associated with each post are stored in the platform_xrf table.
When a post gets duplicated I need to also duplicate the associated rows in the platform_xrf table and then update these new rows with the new post id.
The problem I am having is my SET @postid and SET @newpostid.
If I take out the LIMIT 1 the queries fail but if I keep it in and there are two or more post getting duplicated it will only duplicate one.