PHP mt_getrandmax Function

Malhar Lathkar
Updated on 30-Jun-2020 07:06:54

169 Views

Definition and UsageThe 'mt' prefix in function's name stands for Mersenne Twister. The mt_ getrandmax() function returns largest integer that can be used in PHP. This function uses Mersenne Twister Random Number Generator method. Value returned by this function serves as the upper limit for mt_rand() function to generate random number.This function always returns an integer.Syntaxmt_getrandmax ( void ) : intParametersSr.NoParameter & Description1This function needs no parametersReturn ValuesPHP mt_getrandmax() function use Mersenne Twister Random Number Generator method. and returns largest possible integer that can be used in PHP. On 64 bit Windows, the number is 2147483647PHP VersionThis function is available ... Read More

MySQL SELECT with DISTINCT ID

George John
Updated on 30-Jun-2020 07:06:04

2K+ Views

You can use GROUP BY command for select with distinct id. The syntax is as follows −SELECT *FROM yourTableName GROUP BY yourColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DistinctIdDemo    -> (    -> Id int,    -> Name varchar(20),    -> Age int    -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command. Here, we have added ID with duplicate values.The query is as follows −mysql> insert into DistinctIdDemo values(1, 'Mike', 23); Query OK, 1 row ... Read More

PHP min() Function

Malhar Lathkar
Updated on 30-Jun-2020 07:05:17

346 Views

Definition and UsageThe min () function returns lowest element in array, or lowest amongst two or more comma separated parameters.Syntaxmin ( array $values ) : mixedOrmin ( mixed $value1 [, mixed $... ] ) : mixedParametersSr.NoParameter & Description1valuesIf only one parameter is given, it should be an array of valaues which may be of same or different types2value1, value2, ..If two or more parameters aregiven, they should be any comparable values of same or different typesReturn ValuesPHP min() function returns lowest value from the array parameter or sequence of values. Standard comparison operators are applicable. If multiple values of different types evaluate ... Read More

Best Datatype for Currencies in MySQL

Arjun Thakur
Updated on 30-Jun-2020 07:03:33

201 Views

The best data type for currencies in MySQL is a DECIMAL. The syntax of DECIMAL data type is as follows −DECIMAL(TotalDigit, NumberOfDigitAfterDecimalPoint);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CurrenciesDemo    -> (    -> TotalPrice DECIMAL(10, 2)    -> ); Query OK, 0 rows affected (1.82 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into CurrenciesDemo values(1647575.67); Query OK, 1 row affected (0.19 sec) mysql> insert into CurrenciesDemo values(1647575); Query OK, 1 row affected (0.21 sec) ... Read More

MySQL BETWEEN Without Endpoints

Ankith Reddy
Updated on 30-Jun-2020 07:01:10

260 Views

If you do not want to include the end value in between, then use the following syntax −SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and    yourColumnName not in (yourEndingValue );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table BetweenWithoutEndPoints    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.54 sec)Now you can insert some records in the table using insert command. The ... Read More

MySQL BETWEEN Clause Without Beginning and Endpoints

Chandu yadav
Updated on 30-Jun-2020 06:56:34

90 Views

If you do not want to include start and end value in between, then use the following syntax −SELECT * FROM yourTableName WHERE yourColumnName BETWEEN yourStartingValue and yourEndingValue and    yourColumnName not in (yourStartingValue , yourEndingValue );To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table BetweenWithoutEndPoints    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.54 sec)Now you can insert some records in the table using ... Read More

Select Distinct Combinations from Two Columns in MySQL

George John
Updated on 30-Jun-2020 06:53:01

4K+ Views

To select distinct combinations from two columns, you can use CASE statement. Let us create a table with some columns.The query to create a table is as follows −mysql> create table select_DistinctTwoColumns    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> FirstValue char(1),    -> SecondValue char(1),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.57 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into select_DistinctTwoColumns(FirstValue, SecondValue) values('s', 't'); Query OK, 1 row affected (0.12 sec) mysql> insert into select_DistinctTwoColumns(FirstValue, SecondValue) ... Read More

Insert Sequential Number in MySQL

Chandu yadav
Updated on 30-Jun-2020 06:49:28

1K+ Views

You can insert sequential number in MySQL using session variable. The syntax is as follows −SELECT @anyVariableName − = anyIntegerValue; UPDATE yourTableName SET yourColumnName = @anyVariableName − = @anyVariableName+IncrementStep;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SequentialNumberDemo    -> (    -> SequentialNumber int not null    -> ); Query OK, 0 rows affected (0.84 sec)Insert records in the table using insert command. The query is as follows −mysql> insert into SequentialNumberDemo values(100); Query OK, 1 row affected (0.11 sec) mysql> insert into SequentialNumberDemo values(10); ... Read More

Order By Last 3 Characters in MySQL

George John
Updated on 30-Jun-2020 06:48:25

19K+ Views

You can use ORDER BY RIGHT() function to order by last 3 chars in MySQL. The syntax is as follows −SELECT *FROM yourTableName ORDER BY RIGHT(yourColumnName, 3) yourSortingOrder;Just replace the ‘yourSortingOrder’ to ASC or DESC to set the ascending or descending order respectively.To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table OrderByLast3Chars    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT,    -> EmployeeName varchar(20),    -> EmployeeAge int,    -> PRIMARY KEY(EmployeeId)    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in ... Read More

Add Static Value While Inserting into MySQL with Select

Chandu yadav
Updated on 30-Jun-2020 06:47:02

13K+ Views

You can add static value when you use INSERT INTO SELECT MySQL query. Write the value directly in the select statement or you can add with the help of variable which initializes the value.Case 1 − Place the value directly in the INSERT INTO SELECT statement. The syntax is as follows −INSERT INTO yourSecondTableName(yourColumnName1, yourColumnName2, ....N)    SELECT yourColumnName1 ,yourColumnName2, .....N, yourStaticValue from yourFirstTableName;Case 2 − Add using variable. The syntax is as follows −SET @yourVariableName − = yourstaticValue;    INSERT INTO yourSecondTableName(yourColumnName1, yourColumnName2, ....N)    SELECT yourColumnName1 ,yourColumnName2, .....N, @yourVariableName from yourFirstTableName;To understand the above syntax, you need to ... Read More

Advertisements