-1

Current title values under article table are, for example:

  • Sample Title 1
  • SaMpLE Title 2
  • sample title 3

I have to change the first characters to upper case and the following characters to lower case.

They should be like below after the transaction:

  • Sample title 1
  • Sample title 2
  • Sample title 3

Which SQL command should I use to change all data of the title using a MySQL query and change them permanently?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Then why did you tagged PHP. Do you want it to be done with PHP as an alternative – Narendrasingh Sisodia Oct 03 '15 at 12:51
  • No, sorry. I removed the php tag. – Onur Aydın Oct 03 '15 at 12:54
  • change as in how, display or permanently? two different animals altogether ;-) – Funk Forty Niner Oct 03 '15 at 12:54
  • 2
    Well first you do a google for __mysql string function__ and then you get to this [page of the manual](https://dev.mysql.com/doc/refman/5.0/en/string-functions.html) Then you read it, and decide which function best suites your needs. Then you test it until you get it right. – RiggsFolly Oct 03 '15 at 12:54
  • There's a function named [`LOWER`](https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_lower) for converting strings into lower and for making first word capital you can check [mysql-string-function-equivalent-to-php-ucwords-function](http://stackoverflow.com/questions/2866309/mysql-string-function-equivalent-to-php-ucwords-function) – Narendrasingh Sisodia Oct 03 '15 at 12:55
  • I want to change them permanently. – Onur Aydın Oct 03 '15 at 12:55
  • The accepted answer does not use SQL as stated in the heading -- it uses PHP -> ```ucfirst($foo);```. – Kristoffer Bohmann Oct 03 '15 at 13:34

2 Answers2

2

Apparently, this works:

CONCAT(UPPER(SUBSTRING(title, 1, 1)),LOWER(SUBSTRING(title, 2)))
Tempestas Ludi
  • 1,113
  • 9
  • 24
  • Hope you dont mind I just added the LOWER to lower case all the other characters – RiggsFolly Oct 03 '15 at 12:58
  • #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONCAT(UPPER(SUBSTRING(title, 1, 1)),LOWER(SUBSTRING(title, 2)))' at line 1 – Onur Aydın Oct 03 '15 at 13:19
0

use ucfirst(); function in PHP. By first retrieving it in a variable and then Pass it to a ucfirst(); function and echo the answer.

<?php
  $foo = 'hello world!';
  $foo = ucfirst($foo);             // Hello world!

  $bar = 'HELLO WORLD!';
  $bar = ucfirst($bar);             // HELLO WORLD!
  $bar = ucfirst(strtolower($bar)); // Hello world!
?>
oreopot
  • 3,392
  • 2
  • 19
  • 28
  • #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONCAT(UPPER(SUBSTRING(title, 1, 1)),LOWER(SUBSTRING(title, 2)))' at line 1 – Onur Aydın Oct 03 '15 at 13:59
  • @OnurAydın let me cross check. – oreopot Oct 03 '15 at 14:04