PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
How would I go about updating all rows in a table in MySQL through PHP where one field equals 0? I've actually tried the following SQL in phpMyAdmin and it works fine, but I can't seem to get it to work through my PHP script.
$final_sql = "UPDATE reminders SET checked = 0 WHERE checked = 1";
$final_nt = mysql_query($final_sql) or die(mysql_error());
I thought it would work fine, but there does seem to be a problem. As I said, the SQL did work when I tried it through phpMyAdmin. It's probably so simple and staring me right in the face!
It's supposed to alter all those equalling 1 and change them to 0. As I said, the SQL seemed to work fine in phpMyAdmin, but won't in my php script. Whenever I run it, for some reason it simply won't update anything.
If you've executed the script in PHPMyAdmin... then there wouldn't be anything to update, as the fields are already set to what you want via the query through PHPMyAdmin.
Unless you were doing sample data or the likes.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
scottayy wrote:If you've executed the script in PHPMyAdmin... then there wouldn't be anything to update, as the fields are already set to what you want via the query through PHPMyAdmin.
Unless you were doing sample data or the likes.
I've been reseting the data whilst testing. But does the code look ok? Should it be working?
Providing you have the correct database connection, and the table `reminders` exists in that database, and those field names are correct, and mysql_error()) isn't giving you an error, then yes.. it looks perfect.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
$numr = mysql_query("SELECT count(*) FROM `reminders` WHERE `checked` = 1") or die(mysql_error());
$num = mysql_result($numr,0);
echo '<p>Number To Correct: '.$num.'</p>';
mysql_query("UPDATE `reminders` SET `checked` = 0 WHERE `checked` = 1") or die(mysql_error());
echo '<p>Query to correct successfully executed.</p>';
$numr = mysql_query("SELECT count(*) FROM `reminders` WHERE `checked` = 1") or die(mysql_error());
$num = mysql_result($numr,0);
echo '<p>Number To Correct After Query Executed: '.$num.'</p>';
After running that code, the result you should expect would look like
Number To Correct: 124
Query to correct successfully executed.
Number To Correct After Query Executed: 0
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.