Jump to content

[SOLVED] Delete Where x = y?


Warptweet

Recommended Posts

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

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.

<?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.

Archived

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

×
×
  • 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.