+2  A: 

When you run update, it invalidates the hidden statement hander in your db and the results associated with it.

db->query("SELECT …") -- creates the handler

-- 1st iteration
db->fetchassoc() -- fetches the first row
db->query("UPDATE …") -- creates another handler and destroys the old one

-- 2nd iteration
db->fetchassoc() -- no rows returned by `UPDATE`, nothing to fetch

What you are trying to do, can be done more easily using a single statement:

UPDATE  accounts
SET     installed = DATE_FORMAT(STR_TO_DATE(installed, @current_format_string), '%Y-%d-%m')

, where @current_format_string is how your dates are formatted now.

Update:

Try running this query:

UPDATE  accounts
SET     installdate = DATE_FORMAT(STR_TO_DATE(installdate , '%m/%d/%Y'), '%Y-%d-%m')

Before you run UPDATE query, you may want to check the results with SELECT:

SELECT  DATE_FORMAT(STR_TO_DATE(installdate, '%m/%d/%Y'), '%Y-%d-%m')
FROM    accounts
Quassnoi
so would i be better off pushing all the vars into an array and then doing a for each? or how can i fix it?
mlebrun15
PERFECT. I've honestly spent a few hours and couldn't see what was interfering. thank you so much!
mlebrun15
`@mlebrun15`: what is really better is that you do it on the `MySQL` side as show in the post.
Quassnoi
it keeps setting the values to null. is your var "installed", thats supposed to be the same as the column name right?
mlebrun15
Yes. Could you please post some rows that are contained in the table now?
Quassnoi
the column is set up so all the days are in n/j/Y so 6/23/2009 or 12/2/2009, doesn't str_to_time return a value in Y-m-d? i only ask because, this is what i'd like to convert the date to so i technically wouldn't need the DATE FORMAT correct?
mlebrun15
it doesn't recognize INSTALLDATE as a field? when i check it with the select statement? get undefined index errors.
mlebrun15
`@mlebrun15`: sorry, I read your field name incorrectly. Try now.
Quassnoi
yea, i fixed that, and it still is showing nulls, how do i check the select statement?
mlebrun15
hm. i figured it out. i had <pre><code>DATE_FORMAT(STR_TO_DATE(installdate, '%n/%d/%Y'), '%Y-%d-%m')</code></pre>then i switched to<pre><code>DATE_FORMAT(STR_TO_DATE(installdate, '%m/%d/%Y'), '%Y-%d-%m')</code></pre>you can't use %n in teh str_to_date function?
mlebrun15
figured that out too the php date var of %n = %c in mysql if anyone else comes across this.
mlebrun15