PHP dependant foreach loop -
I'm trying to complete here, to store a database, firstname, lastname combo is to be separated. I've already added new columns to the database to keep the first and last names. What I need to do now is to actually separate them and run a SQL update against the changes.
Can someone give me a hand? Thank you.
This is my code
& lt ;? Php $ link = mysql_connect ('localhost', 'root', ''); Mysql_select_db ("test", $ link); $ Sql = "SELECT * new_users"; $ Result = mysql_query ($ sql); While ($ line = mysql_fetch_assoc ($ result)) {$ foo [] = $ line; } Foreach ($ name $ foo) {$ _name [] = Explosion (',', $ name ['name']); $ _pan [] = $ name ['panamar']; } Foreach ($ PAN $ as PAN) {foreach ($ _ name $ name) {echo '
If I understand your question, then you have a name column Which is "first, last" and you want to change it with the first and last column
The string change of SQL is probably the easiest:.
updated new_users SET first = SUBSTRING_INDEX (name, ",", 1), last = SUBSTRING_INDEX (name, ",", -1)
After that, make sure that it works correctly:
optional table new_users DROP name
Comments
Post a Comment