I am trying to create a PHP script which will update one table with a '1' when a date value in another table is greater or equal to the current date. This is based on an id field which is present in both tables. I have tested the following code with no success - it gives an error for the foreach loop:
<?php
$db_conn = mysql_connect('localhost', '***', '****');
mysql_select_db('db', $db_conn);
$info = mysql_query("SELECT * FROM user_profiles");
$fetch = mysql_fetch_array($info);
foreach($fetch['user_id'] as $id) {
$result = mysql_query("SELECT id
FROM users
WHERE EXISTS (
SELECT user_id
FROM user_profiles
WHERE DATE(profile_value) >= DATE(NOW())
AND users.id = user_profiles.user_id)", $db_conn);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$user_del_result = mysql_query("UPDATE users.block
WHERE user_id = {$row['user_id']}
SET block ='1'
LIMIT 1", $db_conn);
}
}
?>
Both tables contain the same amount of rows (users).
Any help would be great.
Edit
I have narrowed it down to the following:
<?php
$db_conn = mysql_connect('localhost', '***', '****');
mysql_select_db('db', $db_conn);
$info = mysql_query("SELECT * FROM user_profiles");
$fetch = mysql_fetch_array($info);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$user_del_result = mysql_query("UPDATE users
WHERE user_id = {$row['id']}
AND WHERE Date(profile_value ) >= DATE(NOW())
SET block ='1'", $db_conn);
}
?>
However the following error is now thrown: Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Job.php on line 10
Ok now I'm confused...
<?php
$db_conn = mysql_connect('localhost', '', '');
mysql_select_db('_db', $db_conn);
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$result = mysql_query("SELECT id
FROM users
WHERE EXISTS (
SELECT user_id
FROM user_profiles
WHERE DATE(profile_value) >= DATE(NOW())
AND users.id = user_profiles.user_id)", $db_conn);
$user_del_result = mysql_query("UPDATE users
WHERE user_id = {$row['id']}
AND WHERE Date(profile_value ) >= DATE(NOW())
SET block ='1'", $db_conn);
}
?>
Error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Job.php on line 14