3dhomejoe
Member
- Messages
- 66
- Reaction score
- 0
- Points
- 6
Hello, im trying to build a script that gets the date of an old row and select an ID number from it and then it would remove any rows the = that ID number, here is my code so far
it selects all of the id numbers but I can't get it to clear them, what is wrong?
I have posted this on other sites too but no-one has been able to help me yet after about a month or so, im hoping that someone here can help me out X+)
Below im going to post the code and some of the things that I have tried...
My starting code...
Then gave this a try, it gave a white page...
Then re did the code to make it like this, still gave me a white page...
Then I was told to try this
and it just kept on running, after about an hour of running, I killed the command, it did remove everything by request, but it was stuck in a loop
Ran this in my console...
and last but not least, gave this a try
and gave me this...
I hope I did not lose someone between everything, but im clueless at why this does not work, I thought this was going to be an easy script to make but its starting to be a pain in the (INSERT WORD HERE).
Thanks for your help
Joe
it selects all of the id numbers but I can't get it to clear them, what is wrong?
I have posted this on other sites too but no-one has been able to help me yet after about a month or so, im hoping that someone here can help me out X+)
Below im going to post the code and some of the things that I have tried...
My starting code...
PHP:
<?php
$con = mysql_connect('10.0.1.65','3dhomejoe','PASSWORDHERE');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("eq2", $con);
$result = mysql_query("SELECT encid FROM encounter_table where starttime < DATE_SUB(CURDATE(),INTERVAL 30 DAY)");
if(!$result) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "Nothing to do.";
} else {
while($row = mysql_fetch_array($result))
{
//echo "Clearing";
echo $row[0];
mysql_query("DELETE FROM attacktype_table WHERE encid=$encid");
}
}
mysql_close($con);
?>
Then gave this a try, it gave a white page...
PHP:
mysql_query("DELETE FROM attacktype_table WHERE encid="$encid"");
Then re did the code to make it like this, still gave me a white page...
PHP:
<?php
$con = mysql_connect('10.0.1.65','3dhomejoe','PASSWORDHERE');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("eq2", $con);
mysql_query("DELETE FROM attacktype_table WHERE encid IN (SELECT encid FROM encounter_table WHERE startime < DATE_SUB(CURDATE(),INTERVAL 30 DAY)");
}
}
mysql_close($con);
?>
Then I was told to try this
PHP:
<?php
$con = mysql_connect('10.0.1.65','3dhomejoe','PASSGOESHERE');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("eq2", $con);
$query = "DELETE FROM attacktype_table WHERE encid IN (SELECT encid FROM encounter_table WHERE starttime < DATE_SUB(CURDATE(),INTERVAL 30 DAY))";
mysql_query($query) or die('MySQL error: ' . mysql_error() . "<br>\nQuery: $query");
mysql_close($con);
?>
and it just kept on running, after about an hour of running, I killed the command, it did remove everything by request, but it was stuck in a loop
Ran this in my console...
[root@moomoo ~]# mysqladmin -u 3dhomejoe -p PROCESSLIST
Enter password:
+------+-----------+----------------------+--------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+-----------+----------------------+--------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| 2943 | 3dhomejoe | http-159df05bee:2575 | eq2 | Sleep | 462 | | |
| 2946 | 3dhomejoe | 10.0.1.52:4384 | eq2 | Query | 747 | Sending data | DELETE FROM attacktype_table WHERE encid IN (SELECT encid FROM encounter_table WHERE starttime < DAT |
| 2954 | 3dhomejoe | http-159df05bee:2645 | information_schema | Sleep | 472 | | |
| 2961 | 3dhomejoe | http-159df05bee:2667 | mysql | Sleep | 454 | | |
| 2972 | 3dhomejoe | http-159df05bee:2695 | | Sleep | 205 | | |
| 2984 | 3dhomejoe | localhost | | Query | 0 | | show processlist |
+------+-----------+----------------------+--------------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
[root@moomoo ~]#
and last but not least, gave this a try
PHP:
$query = "DELETE a FROM attacktype a INNER JOIN encounter_table e WHERE a.encid = e.encid and e.starttime < DATE_SUB(CURDATE(),INTERVAL 30 DAY);";
MySQL error: Table 'eq2.attacktype' doesn't exist
Query: DELETE a FROM attacktype a INNER JOIN encounter_table e WHERE a.encid = e.encid and e.starttime < DATE_SUB(CURDATE(),INTERVAL 30 DAY);
I hope I did not lose someone between everything, but im clueless at why this does not work, I thought this was going to be an easy script to make but its starting to be a pain in the (INSERT WORD HERE).
Thanks for your help
Joe