Changing php function to database function

When $myTable[‘title’] is “abcdeK”, I like to choose “abcde”.
When $myTable[‘title’] is “xyzA”, I like to choose “xyz”.

The code below is for it…

$removedTitle = substr($myTable['title'], 0, -1) ;

$updateMyTable = $databaseConnect->query("update myTable
set myColumn = '$removedTitle' where moyID = $myID");

The code above works filne.

I like to use database function instead of the php variable " $removedTitle".
The code below which does not work correctly is one of my trials for it…

$updateMyTable = $databaseConnect->query("update myTable
set myColumn = substr('$myTable[title]', 0, -1) where moyID = $myID");

Is there any database code instead of the php code of the above?

What does it do that it should not, or what does it not do that it should?

What database are you using? If it’s MySQL, it sounds as if you might be looking for a combination of LENGTH() and LEFT().

You should really be using Prepared Statements rather than concatenating data strings into queries like that.

joon is going to want you to actually provide this solution


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.