Display Specified Values Inside IN Clause with MySQL

AmitDiwan
Updated on 31-Dec-2019 08:13:56

133 Views

For this, you can use IN() along with ORDER BY clause. Let us first create a table −mysql> create table DemoTable1986    (    Number int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1986 values(50); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(60); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(100); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(200); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1986 values(350); Query OK, 1 row ... Read More

jQuery Index with Examples

AmitDiwan
Updated on 31-Dec-2019 08:13:05

298 Views

The index() method in jQuery is used to return the index position of specified elements relative to other specified elements.SyntaxThe syntax is as follows −$(selector).index()ExampleLet us now see an example to implement the jQuery index() method − Live Demo    $(document).ready(function(){       $("li").click(function(){          document.getElementById("demo").innerHTML = $(this).index();       });    }); Devices TV Laptop Headphone Earphone SSD Index = OutputThis will produce the following output −Now, to get the index of any of the list items, just click on it as shown below. We clicked “Headphone” here −

Convert Dates Like Jan 2017 and May 2018 to Complete Date in MySQL

AmitDiwan
Updated on 31-Dec-2019 08:11:30

215 Views

For this, use STR_TO_DATE() along with DATE_FORMAT(). Let us first create a table −mysql> create table DemoTable1985    (    DueDate varchar(20)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1985 values('Jan 2017'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1985 values('May 2018'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1985 values('Aug 2015'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1985;This will produce the following output −+----------+ | DueDate  | ... Read More

jQuery toggleClass with Examples

AmitDiwan
Updated on 31-Dec-2019 08:10:40

330 Views

The toggleClass() method in jQuery is used to toggle between adding or removing one or more classes from selected elements.SyntaxThe syntax is as follows −$(selector).toggleClass(classname, func(index, currentclass), switch)Above, class name specifies one or more class names to add or remove, whereas func is a function that returns one or more class names to add or remove.ExampleLet us now see an example to implement the jQuery toggleClass() method − Live Demo    $(document).ready(function(){       $("button").click(function(){          $("p").toggleClass("demo");       });    }); .demo {    background-color: orange;    color: white;   ... Read More

Change Date in Table with Date Records in MySQL

AmitDiwan
Updated on 31-Dec-2019 08:09:27

727 Views

Let’s say you need to change the date and add years. For this, use UPDATE command along with DATE_ADD(). Let us first create a table −mysql> create table DemoTable1984    (    ShippingDate date    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1984 values('2014-01-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1984 values('2015-12-23'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1984 values('2017-10-31'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1984 values('2018-06-01'); Query OK, 1 row affected (0.00 sec)Display all ... Read More

Insert Row with Timestamp X Days Ago in MySQL

AmitDiwan
Updated on 31-Dec-2019 08:08:24

312 Views

To insert a row like this use the following syntax, wherein we are using CURRENT_TIMESTAMP −insert into yourTableName values(CURRENT_TIMESTAMP - INTERVAL ABS(RAND() * 100) DAY);To understand the above syntax, let us create a table −mysql> create table DemoTable1983    (    DueDate timestamp    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1983 values(CURRENT_TIMESTAMP - INTERVAL ABS(RAND() * 100) DAY); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1983 values(CURRENT_TIMESTAMP - INTERVAL ABS(RAND() * 100) DAY); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1983 ... Read More

jQuery removeData Method with Examples

AmitDiwan
Updated on 31-Dec-2019 08:07:33

164 Views

The removeData() method in jQuery is used to remove the data set with the data() method.SyntaxThe syntax is as follows −$(selector).removeData(name)Above, the name parameter is used to specify the name of the data to remove.ExampleLet us now see an example to implement the jQuery removeData() method − Live Demo    $(document).ready(function(){       $(".button1").click(function(){          $("div").data("student", "Jack Sparrow");          alert("Student Name = " +$("div").data("student"));       });       $(".button2").click(function(){          $("div").removeData("student");          alert("Student Name = " +$("div").data("Jack Sparrow"));       }); ... Read More

Change Table Engine from InnoDB to MyISAM in MySQL

AmitDiwan
Updated on 31-Dec-2019 08:06:19

371 Views

Let us first create a table −mysql> create table DemoTable1982    (    StudentId int    ,    StudentName varchar(20),    StudentAge int    ); Query OK, 0 rows affected (0.00 sec)Let us check the table engine type -mysql> show create table DemoTable1982;This will produce the following output −+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table         | Create Table                                                                                     ... Read More

imagecreatetruecolor Function in PHP

Arjun Thakur
Updated on 31-Dec-2019 08:05:48

984 Views

The imagecreatetruecolor() function creates a new true color image.Syntaximagecreatetruecolor (width , height )Parameterswidth: The image width.height: The image height.ReturnThe imagecreatetruecolor() function returns an image resource identifier on success, FALSE on errors.ExampleThe following is an example Live DemoOutputThe following is the output displaying the height and width of the new image:500 600ExampleLet us see another example with different height and width: Live DemoOutputThe following is the output displaying the height and width of the new image:450 300

Calculate Sum from 5 Tables with a Similar Column in MySQL

AmitDiwan
Updated on 31-Dec-2019 08:02:41

526 Views

For this, use UNION ALL along with SUM(). Let us create 5 tables −mysql> create table DemoTable1977    (    UP int    ); Query OK, 0 rows affected (0.00 sec) mysql> insert into DemoTable1977 values(10); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1977 values(20); Query OK, 1 row affected (0.00 sec) mysql> select * from DemoTable1977; +------+ | UP   | +------+ |   10 | |   20 | +------+ 2 rows in set (0.00 sec) mysql> create table DemoTable1978    (    UP int    ); Query OK, 0 rows affected (0.00 sec) mysql> ... Read More

Advertisements