AmitDiwan has Published 10744 Articles

How to trim all strings in an array in PHP ?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 08:11:27

1K+ Views

To trim all strings in an array in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Array with leading and trailing whitespaces... Value = John Value = Jacob Value = Tom Value = Tim Updated Array... Value = John Value = Jacob Value = Tom Value = ... Read More

Sort an array of dates in PHP

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 08:08:28

3K+ Views

To sort an array of dates in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Array (    [0] => 2019-08-10    [1] => 2019-09-08    [2] => 2019-10-10    [3] => 2019-11-11 )ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Array ( ... Read More

How to re-index an array in PHP?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 08:04:03

775 Views

To re-index an array in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−Array... Key = 0, Value = 150  Key = 1, Value = 100 Key = 2, Value = 120 Key = 3, Value = 110 Key = 4, Value = 115 Array after ... Read More

Concatenate two values from the same column with different conditions in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:35:39

1K+ Views

For this, you can use group_concat() with aggregate function. Let us first create a table −mysql> create table DemoTable1869      (      Id int,      Subject varchar(20 ),      Name varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table ... Read More

How to derive value of a field from another field in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:31:05

427 Views

For this, you can use the concept of user defined variable. Let us first create a table −mysql> create table DemoTable1868      (      Value int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1868 ... Read More

How to list all variables initialized by SET operator in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:22:55

304 Views

To list all variables initialized by SET operator, the syntax is as follows −select * from performance_schema.user_variables_by_thread;Here is the query to set the variable −mysql> set @FirstName='John'; Query OK, 0 rows affected (0.00 sec) mysql> set @LastName='Doe'; Query OK, 0 rows affected (0.00 sec)Here is the query to display the ... Read More

Increment date/time value by second with MySQL query?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:21:06

563 Views

For this, use date_add() with interval command. Let us first create a table −mysql> create table DemoTable1867      (      ArrivalTime datetime      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1867 values('2019-10-12 12:34:45'); Query OK, ... Read More

MySQL query to get string from one column and find its position in another column with comma separated values?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:19:48

298 Views

For this, use FIND_IN_SET(). Let us first create a table −mysql> create table DemoTable1866      (      Value1 int,      ListOfValues varchar(100)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1866 values(56, '78, 56, ... Read More

Trying to round a calculation to two decimal places in a new column with MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:18:00

516 Views

To round, use MySQL ROUND() function. Let us first create a table −mysql> create table DemoTable1865      (      Value1 int,      Value2 int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1865 values(40, ... Read More

How to assign the result of a MySQL query into a variable?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 07:16:28

1K+ Views

Use @anyVariableName to assign the result of a query into a variable. Let us first create a table −mysql> create table DemoTable1864      (      Id int,      FirstName varchar(20),      LastName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in ... Read More

Advertisements