0
include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$query = mysql_fetch_array($selectrow, MYSQL_ASSOC);
//Run business removal
if ($query['Enable'] == "true"){
	if ($query['autoRemove'] <= "0"){
	$removeSQL = "DELETE FROM AccLink WHERE autoRemove <= 0";
	mysql_query($removeSQL);
	echo "Business Removed. {$query['username']}<br>";
	}
	$remove1 = "Update AccLink SET autoRemove = autoRemove -1";
	mysql_query($remove1);
	echo "Run Sucessfull {$query['username']}<br>";
	}

Can anyone see anything wrong with this, it just doesnt seem to remove the buisness.

The process is, each day it will be run and the figure in the mysql database will be the value -1 depending if the column name "enable" is set to true and when it reaches 0 it should remove the row.

i cant get it to work.

also there is about 20 - 30 rows in there that should get the -1.

3
Contributors
10
Replies
11
Views
8 Years
Discussion Span
Last Post by somedude3488
0

You had extra quotes in there. Try this:

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$query = mysql_fetch_array($selectrow, MYSQL_ASSOC);
//Run business removal
if ($query['Enable'] == "true"){
	if ($query['autoRemove']<=0){
	$removeSQL = "DELETE FROM AccLink WHERE autoRemove <= 0";
	mysql_query($removeSQL);
	echo "Business Removed. {$query['username']}<br>";
	}
	$remove1 = "Update AccLink SET autoRemove = autoRemove -1";
	mysql_query($remove1);
	echo "Run Sucessfull {$query['username']}<br>";
	}
0

You are running mysql_fetch_array only once, which means the code will only be run for one row. Is this what you are wanting?

I see that you have queries that update multiple rows based on the value of the first row returned. I am not sure of how the data in the rows is formatted, but your setup doesn't make sense to me. You might need to rethink how you are doing this.

0

I guess based on what kkeith29 said, your script would look more like the following:

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$remove1 = "Update AccLink SET autoRemove = autoRemove -1";
mysql_query($remove1);
$removeSQL = "DELETE FROM AccLink WHERE autoRemove <= 0";
$r = mysql_query($removeSQL);
echo mysql_affected_rows($r).' rows were deleted.';
0

Yeah but how do i determine if the [enable] column is set to true, and if it is to run the above, else do nothing.

0

If you want to do it where the enable column is true then try the following:

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$remove1 = "Update AccLink SET autoRemove = autoRemove -1 WHERE enable='true'";
mysql_query($remove1);
$removeSQL = "DELETE FROM AccLink WHERE enable='true' AND autoRemove <= 0";
$r = mysql_query($removeSQL);
echo mysql_affected_rows($r).' rows were deleted.';

or

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$remove1 = "Update AccLink SET autoRemove = autoRemove -1 WHERE Enable='true'";
mysql_query($remove1);
$removeSQL = "DELETE FROM AccLink WHERE Enable='true' AND autoRemove <= 0";
$r = mysql_query($removeSQL);
echo mysql_affected_rows($r).' rows were deleted.';
0

If you want to do it where the enable column is true then try the following:

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$remove1 = "Update AccLink SET autoRemove = autoRemove -1 WHERE enable='true'";
mysql_query($remove1);
$removeSQL = "DELETE FROM AccLink WHERE enable='true' AND autoRemove <= 0";
$r = mysql_query($removeSQL);
echo mysql_affected_rows($r).' rows were deleted.';

or

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$remove1 = "Update AccLink SET autoRemove = autoRemove -1 WHERE Enable='true'";
mysql_query($remove1);
$removeSQL = "DELETE FROM AccLink WHERE Enable='true' AND autoRemove <= 0";
$r = mysql_query($removeSQL);
echo mysql_affected_rows($r).' rows were deleted.';

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/sites/****/public_html/Login/tools/autoControl/autoremove.php on line 9
rows were deleted.Emailed sucess email

0

Perhaps there is an error in the mysql query with how the table structure is setup. Try the following and make sure the columns casing is correct.

include"../../pages/config.php";
$selectrow = mysql_query("SELECT * FROM members");
$remove1 = "Update AccLink SET autoRemove = autoRemove -1 WHERE Enable='true'";
mysql_query($remove1) or die('error1:<br>'.mysql_error());
$removeSQL = "DELETE FROM AccLink WHERE Enable='true' AND autoRemove <= 0";
$r = mysql_query($removeSQL) or die('error2:<br>'.mysql_error());
echo mysql_affected_rows($r).' rows were deleted.';

Hope that helps.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.