OK - I've updated my code to mysqli. Below -
I am still running into a problem on the second row, the update fails.
Building an array of the id's returned in my select statement is my next step and then I'll
<?php
// CONNECT TO THE DATABASE
$DB_NAME = 'businessprocessmanager';
$DB_HOST = 'localhost';
$DB_USER = 'jim';
$DB_PASS = 'bddbdd';
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// A QUICK QUERY ON A Notification TABLE
$query = "SELECT\n"
. "`id`,`DaysToReview`,\n"
. "`DaysPastReview`,\n"
. "`reviewDueDate`,\n"
. "`assignedDays`,\n"
. "`assignedDate`,\n"
. "`Msg`,\n"
. "`name`,\n"
. "`role`,\n"
. "`EMail`\n"
. " FROM `notification`\n"
. " WHERE `emaildate` is null \n"
. " ORDER BY `Email`, `priority` ";
//$query = "SELECT * FROM `users` WHERE `status`='bonkers'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
//$prev_email=mysqli_result($result,$i,"Email");
//$email=$prev_email;
//$row = $result->fetch_array();
//$prev_email = "";
//$email = $prev_email;
//echo $prev_email . " " . $email;
// GOING THROUGH THE DATA
if($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{
print_r( $row );
$id = $row['id'];
//echo "Row is - ".$row."Id = ".$id."\n";
$days_to_review=$row['DaysToReview'];
$days_past_review=$row['DaysPastReview'];
$review_due_date=$row['reviewDueDate'];
$assigned_days=$row['assignedDays'];
$assigned_date=$row['assignedDate'];
$msg=$row['Msg'];
$name=$row['name'];
$role=$row['role'];
$email=$row['EMail'];
echo "Email " . $row['EMail'];
// Update each notification column (emailDate) with current_timestamp as you are processing the list.
$sql = "UPDATE `notification` SET `emailDate` = current_timestamp WHERE"
. "`id`= ".$id."\n";
var_dump($sql);
$result = $mysqli->query($sql) or die($mysqli->error.__LINE__);
var_dump($result);
$prev_email = $email;
}
}
else {
echo 'NO RESULTS';
}
// CLOSE CONNECTION
mysqli_close($mysqli);
?>
The output of my code is as follows:
Array
(
[id] => 1
[DaysToReview] => 0
[DaysPastReview] => 41
[reviewDueDate] => 2014-01-31 00:00:00
[assignedDays] => 0
[assignedDate] =>
[Msg] => Review Date Expired
[name] => Electronic Orders
[role] => MANAGER
[EMail] => user@example.com
)
Email user@example.comstring(71) "UPDATE notification SET emailDate = cur
rent_timestamp WHEREid= 1
"
bool(true)
PHP Fatal error: Call to a member function fetch_assoc() on a non-object in H:\
PHP_Scripts\MYSQLI_NotifyA.php on line 47
PHP Stack trace:
PHP 1. {main}() H:\PHP_Scripts\MYSQLI_NotifyA.php:0
Fatal error: Call to a member function fetch_assoc() on a non-object in H:\PHP_S
cripts\MYSQLI_NotifyA.php on line 47
Call Stack:
0.0004 647712 1. {main}() H:\PHP_Scripts\MYSQLI_NotifyA.php:0