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.

Recommended Answers

All 10 Replies

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>";
	}

Still nothing.

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.

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.';

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.

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.';

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

still works tho just get that error

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.

Actually mysql_affected_rows takes the connection to the database itself, not the result of a query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.