Ken2k7 Posted May 4, 2010 Share Posted May 4, 2010 You can (simply) use the mysql STR_TO_DATE() function in the UPDATE query to convert any textual format date into a mysql DATE value - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date Ooh nice. Forgot that one. Good show. Quote Link to comment Share on other sites More sharing options...
topflight Posted May 4, 2010 Author Share Posted May 4, 2010 Cool now thats look a lot eaiser however how can I write that code? If I have over 50 records? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2010 Share Posted May 4, 2010 Cool now thats look a lot eaiser however how can I write that code? If I have over 50 records? Do you understand the code or SQL statements we posted up? Apparently you just run them. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 4, 2010 Share Posted May 4, 2010 An UPDATE query that does not have a WHERE clause will match and therefore operate on all rows in your table. You don't even need any php code as you can execute the query directly against your database using your favorite database management tool. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2010 Share Posted May 4, 2010 I actually spotted an error in my update. Missing a parenthesis. UPDATE members SET last_report_n = CONCAT_WS('-', RIGHT(last_pirep, 4), LEFT(last_pirep, 2), RIGHT(LEFT(last_pirep, LOCATE('.', last_pirep, 3), 2))); Quote Link to comment Share on other sites More sharing options...
topflight Posted May 4, 2010 Author Share Posted May 4, 2010 With the following code the row is still the same: mysql_query("UPDATE members SET last_report_n = CONCAT_WS('-', RIGHT(last_pirep, 4), LEFT(last_pirep, 2), RIGHT(LEFT(last_pirep, LOCATE('.', last_pirep, 3), 2))"); Quote Link to comment Share on other sites More sharing options...
topflight Posted May 5, 2010 Author Share Posted May 5, 2010 any other help? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 5, 2010 Share Posted May 5, 2010 UPDATE members SET last_report_n = STR_TO_DATE(last_pirep,'%m.%d.%Y') Quote Link to comment Share on other sites More sharing options...
topflight Posted May 5, 2010 Author Share Posted May 5, 2010 This is my code and nothing isn't happening. $get = mysql_query("SELECT * FROM members"); while($row = mysql_fetch_assoc($get)){ $id = $row['login']; $od = str_replace('.', '-', strrev($row['last_pirep'])); mysql_query("UPDATE members SET last_report_n = STR_TO_DATE(last_pirep,'%m.%d.%Y')"); } echo'UPDATED Sucessfully!' ?> Quote Link to comment Share on other sites More sharing options...
947740 Posted May 5, 2010 Share Posted May 5, 2010 If you read through what everyone is posting, they are saying you only need to run this ONE query. You can do that through mysql directly, through phpmyadmin, etc. If you want to it through php, this is ALL you need... mysql_query("UPDATE members SET last_report_n = STR_TO_DATE(last_pirep,'%m.%d.%Y')"); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2010 Share Posted May 6, 2010 LOL, topflight, you introduced a typo in the last_report (last_pirep) source field name in the code you posted in Reply #13. That error has carried through to this point in the thread. It is kind of your responsibly to LOOK at the code you post and to look at the code someone else posts in response to make sure it applies to what you are doing. How are we supposed to know that you did not actually have a column by that name or renamed your original column to that name? We only have access to and see the information that you post and have to assume that what you post is accurate, even if it changes during the life of a thread. We are not psychic after all If you correct the last query posted so that it has the correct field name, it will work. And frankly, just posting that something does not work is not helpful. If is also your responsibly to investigate why something is not working on your server with your data. At least look at the code (and queries) you are using that are not working and attempt to find why they are not working. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.