SELECTing and UPDATEing all records
In MySQL database table I want to SELECT each record, change the way a date is formated in one field and write this new format to another field of that record. I want the script to continue through each record and do the whole database table.
I am having a problem with my do while loop. The first record is UPDATE alright, but the I get the error:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\websites\test.php on line 43
Line# 43 is $Row = mysqli_fetch_assoc($QueryResult);
How can I do this?
<?php
$DBConnect = mysqli_connect($host,$user,$password)
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
mysqli_select_db($DBConnect, $DBName)
Or die("<p>Unable to select the database.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$SendQuery = "SELECT * FROM table";
$QueryResult = mysqli_query($DBConnect, $SendQuery)
Or die("<p>Unable to excute the requested query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$Row = mysqli_fetch_assoc($QueryResult);
do {
$TimeStamp = strtotime($Row['old_date_stamp']);
$SendQuery = "UPDATE table
SET date_stamp = '$TimeStamp'
WHERE id = '{$Row['id']}'";
$QueryResult = mysqli_query($DBConnect, $SendQuery)
Or die("<p>Unable to excute the requested query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
echo $Row['id'] . "\t" . $TimeStamp . "\t"
. $Row['old_date_stamp'] . "<br />";
$Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
?>