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!
UPDATE products SET title = 'not available at this time' WHERE title = 'not averlbe at this time'
But I can't because there are more than 5 fields, could be more, with the same spelling error. So I want to do this query, but on ANY field where the text states *.
Anyone know how to do this?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Changing it once in the database is going to be problematic as you have to find out where the spelling errors are. As far as I know there is no way around this intensive problem. It therefore makes sense to check it at the entry point, not fix it once the horse has bolted. I assume you are filling the database in from somewhere. Check and correct the spelling where the user enters the data.
You may want to look at Pspell as one method of doing this.
$tables = mysql_query("SHOW TABLES");
while ($t = mysql_fetch_array($tables)) {
//Columns
$columns = mysql_query("DESCRIBE `".$t[0]."`");
while ($c = mysql_fetch_object($columns)) {
mysql_query("UPDATE `table` SET `".$c->Field."` = 'Not Current Available' WHERE `".$c->Field."` = 'Not curently averible'");
}
//End Columns
}
That will do every table in the database. If you just need to do one table just use the bit between the 'Columns' comments and replace $t[0] with the table name.
(I realise I'm mixing mysql_fetch_array() and mysql_fetch_object() ... the reason is that "SHOW TABLES" returns a field based on the database name so it's easier to access it numerically.)