Warptweet Posted March 20, 2007 Share Posted March 20, 2007 In my MySQL Database, I have a pending_uploads table. It stores the following: uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete Now, I also have another table, called declined_uploads. In the declined_uploads table, it has the following aswell... uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete Now, the DEFAULT for the uploaddelete column in both tables are a value of 'no' But, how would I transfer EVERY ROW with their uploaddelete value of 'yes', to transfer all the info to the declined_uploads table? Because the rows that I want transfered to the declined_uploads table have their uploaddelete value of 'yes' I sort of have this BASE of the code... <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con); mysql_query("INSERT INTO declined_uploads (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')"); mysql_close($con); ?> Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/43535-solved-delete-where-x-y/ Share on other sites More sharing options...
Barand Posted March 20, 2007 Share Posted March 20, 2007 INSERT INTO declined_uploads (uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete) SELECT uploadname, uploadauthor, uploadid, uploaddescription, uploaddelete FROM pending_uploads WHERE uploaddelete='yes' Link to comment https://forums.phpfreaks.com/topic/43535-solved-delete-where-x-y/#findComment-211407 Share on other sites More sharing options...
per1os Posted March 20, 2007 Share Posted March 20, 2007 Remember to back up data before trying this, as I am not sure of the results: <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con); $qu = mysql_query("SELECT uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete FROM pending_uploads WHERE uploaddelete = 'yes'") or DIE(mysql_error()); while ($row = mysql_fetch_array($qu)) { mysql_query("INSERT INTO declined_uploads (uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete) VALUES ('".$row['uploadname']."', '".$row['uploadauthor']."','".$row['uploadid']."','".$row['uploaddescription']."','".$row['uploaddelete']."')"); mysql_query("DELETE FROM pending_uploads WHERE uploadname = '".$row['uploadname']."' AND uploadauthor='".$row['uploadauthor']."' AND uploadid='".$row['uploadid']."' AND uploaddescription = '".$row['uploaddescription']."' AND uploaddelete='".$row['uploaddelete']."' LIMIT 1"); } mysql_close($con); ?> See if that works. Link to comment https://forums.phpfreaks.com/topic/43535-solved-delete-where-x-y/#findComment-211413 Share on other sites More sharing options...
Warptweet Posted March 20, 2007 Author Share Posted March 20, 2007 Frost110, your code works for deleting, but it doesn't transfer any of the database information to the declined_uploads database Do you, or anyone else have a solution to his code? Something is wrong with the declined_uploads part of it. No error is given. Link to comment https://forums.phpfreaks.com/topic/43535-solved-delete-where-x-y/#findComment-211468 Share on other sites More sharing options...
per1os Posted March 20, 2007 Share Posted March 20, 2007 <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con); $qu = mysql_query("SELECT uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete FROM pending_uploads WHERE uploaddelete = 'yes'") or DIE(mysql_error()); while ($row = mysql_fetch_array($qu)) { mysql_query("INSERT INTO declined_uploads (uploadname, uploadauthor,uploadid,uploaddescription,uploaddelete) VALUES ('".$row['uploadname']."', '".$row['uploadauthor']."','".$row['uploadid']."','".$row['uploaddescription']."','".$row['uploaddelete']."')") or DIE(mysql_error()); mysql_query("DELETE FROM pending_uploads WHERE uploadname = '".$row['uploadname']."' AND uploadauthor='".$row['uploadauthor']."' AND uploadid='".$row['uploadid']."' AND uploaddescription = '".$row['uploaddescription']."' AND uploaddelete='".$row['uploaddelete']."' LIMIT 1"); } mysql_close($con); ?> Try that. I most likely messed up the single and double quotes. Report what the mysql_error() is. Link to comment https://forums.phpfreaks.com/topic/43535-solved-delete-where-x-y/#findComment-211471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.