wright67uk Posted June 8, 2011 Share Posted June 8, 2011 Is there a way to change all of my values within a mysql table to proper case? At the moment I have some values as upper and others as lower. I have mysql admin. Is this possible, or would it be easier to transfer my data into excel for processing? Quote Link to comment https://forums.phpfreaks.com/topic/238825-is-there-a-way-to-change-all-of-my-values-within-a-mysql-table-to-proper-case/ Share on other sites More sharing options...
fugix Posted June 8, 2011 Share Posted June 8, 2011 You can simply extract the values from your database and use strtoupper() to convert the data to uppercase. If you want to store the values into your db as uc words. You can use the mysql string function upper() Quote Link to comment https://forums.phpfreaks.com/topic/238825-is-there-a-way-to-change-all-of-my-values-within-a-mysql-table-to-proper-case/#findComment-1227201 Share on other sites More sharing options...
Pikachu2000 Posted June 8, 2011 Share Posted June 8, 2011 It can all be done with one simple query using UCASE() or LCASE(). If you want first letters upper or some other combination that will take a bit of extra work. UPDATE table SET field = LCASE(field) Quote Link to comment https://forums.phpfreaks.com/topic/238825-is-there-a-way-to-change-all-of-my-values-within-a-mysql-table-to-proper-case/#findComment-1227222 Share on other sites More sharing options...
wright67uk Posted June 9, 2011 Author Share Posted June 9, 2011 Thankyou, that is great to know. I do need to change the values to First Letter Capitals but I wasn't too sure if it was possible within mysql. <?php $subtype = $_GET['subtype']; echo "<h1>$subtype</h1>"; $query = "SELECT name, phone, email, WebAddress, postcode FROM business WHERE subtype ='$subtype' AND confirmed ='Yes' ORDER BY name"; if( $result = mysql_query($query) ) { echo mysql_error(); while($row = mysql_fetch_assoc($result) ) { foreach( $row as $k => $v ) { if( empty($v) ) { unset($row[$k]); } } if( !empty($row['postcode']) ) { $row['postcode_link'] = "<p class=link><a href='/gmap.php?postcode=" . urlencode($row['postcode']) . "'>Map</a></p><br>"; } echo implode( '<br>', $row); } } ?> The results in the query above would be using the first letter capitals. Im not bothered if this is stored in mysql or wether it is just formartted in php, just a bit gazumped when it comes to doing it. Quote Link to comment https://forums.phpfreaks.com/topic/238825-is-there-a-way-to-change-all-of-my-values-within-a-mysql-table-to-proper-case/#findComment-1227279 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.