Write PHP Script Using LIKE Clause to Match Data from MySQL Table

Giri Raju
Updated on 22-Jun-2020 14:17:26

434 Views

We can use the similar syntax of the WHERE...LIKE clause into the PHP function – mysql_query(). This function is used to execute the SQL command and later another PHP function – mysql_fetch_array() can be used to fetch all the selected data if the WHERE...LIKE clause is used along with the SELECT command.But if the WHERE...LIKE clause is being used with the DELETE or UPDATE command, then no further PHP function call is required.To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script that will return all the records from the table named ‘tutorial_tbl’ ... Read More

ContainsKey in C#

Ankith Reddy
Updated on 22-Jun-2020 14:17:07

2K+ Views

ContainsKey is a Dictionary method in C# and check whether a key exists in the Dictionary or not.Declare a Dictionary and add elements −var dict = new Dictionary() {    {"TV", 1},    {"Home Theatre", 2},    {"Amazon Alexa", 3},    {"Google Home", 5},    {"Laptop", 5},    {"Bluetooth Speaker", 6} };Now, let’s say you need to check for the existence of a particular element in the Dictionary. For that, use the ContainsKey() method −if (dict.ContainsKey("Laptop") == true) {    Console.WriteLine(dict["Laptop"]); }The following is the code −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() ... Read More

Use VIEWS to Emulate CHECK CONSTRAINT

Fendadis John
Updated on 22-Jun-2020 14:16:24

136 Views

As we know that MySQL supports foreign key for referential integrity but it does not support CHECK constraint. But we can emulate them by using triggers. It can be illustrated with the help of an example given below −ExampleSuppose we have a table named ‘car1’ which can have the fix syntax registration number like two letters, a dash, three digits, a dash, two letters as follows −mysql> Create table car1 (number char(9)); Query OK, 0 rows affected (0.32 sec) mysql> Insert into car1 values('AB-235-YZ'); Query OK, 1 row affected (0.10 sec)The above value is a valid one but what ... Read More

Convert String to Bool in C#

Arjun Thakur
Updated on 22-Jun-2020 14:15:52

2K+ Views

To convert a string to a bool, use the Bool.parse method in C# −Firstly, set a string −string str = "false";Now, convert it to bool −bool.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "false";       bool res = bool.Parse(str);       Console.WriteLine(res);    } }OutputFalse

C# Program to Convert String to Long

Chandu yadav
Updated on 22-Jun-2020 14:15:30

15K+ Views

To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "6987646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "6987646475767";       long res = long.Parse(str);       Console.WriteLine(res);    } }Output6987646475767

Key-Value Pair in C#

George John
Updated on 22-Jun-2020 14:15:06

12K+ Views

The KeyValuePair class stores a pair of values in a single list with C#.Set KeyValuePair and add elements −var myList = new List(); // adding elements myList.Add(new KeyValuePair("Laptop", 20)); myList.Add(new KeyValuePair("Desktop", 40)); myList.Add(new KeyValuePair("Tablet", 60));Here is the code to learn how to work with KeyValuePair and display the keys and values −ExampleUsing System; using System.Collections.Generic; class Program {    static void Main() {       var myList = new List();       // adding elements       myList.Add(new KeyValuePair("Laptop", 20));       myList.Add(new KeyValuePair("Desktop", 40));       myList.Add(new KeyValuePair("Tablet", 60));       foreach (var val in myList) {          Console.WriteLine(val);       }    } }

C# Program to Find the Smallest Element from an Array

Ankith Reddy
Updated on 22-Jun-2020 14:14:43

2K+ Views

Declare an array −int[] arr = { 5, 9, 2, 7 };Now to get the smallest element from an array, use the Min() method −arr.Min());Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 5, 9, 2, 7 };       Console.WriteLine(arr.Min());    } }Output2

Empty List in C#

Samual Sam
Updated on 22-Jun-2020 14:14:20

9K+ Views

Set a list that has zero elements −List myList = new List();Now check whether the list is empty or null −Console.WriteLine(myList == null);Above, returns “False” i.e. the list is not null - the list is empty.Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       List myList = new List();       // returns false i.e. an empty list (not a null list)       Console.WriteLine(myList == null);    } }OutputFalse

C# Program to Loop Over a Two-Dimensional Array

karthikeya Boyini
Updated on 22-Jun-2020 14:13:58

5K+ Views

Declare a two dimensional array −string[, ] array = new string[3, 3];Set elements in the array −array[0, 0] = "One"; array[0, 1] = "Two"; array[0, 2] = "Three"; array[1, 0] = "Four"; array[1, 1] = "Five"; array[1, 2] = "Six"; array[2, 0] = "Seven"; array[2, 1] = "Eight"; array[2, 2] = "Nine";Now, get the upper bound to get the dimensions to loop over the array −int uBound0 = array.GetUpperBound(0); int uBound1 = array.GetUpperBound(1);Iterate through a nested loop, until the above two values as shown in the code below −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo {   ... Read More

C# Program to Display the Previous Day

George John
Updated on 22-Jun-2020 14:13:12

4K+ Views

To display the previous day, use the AddDays() method and a value -1 to get the previous day.Firstly, use the following to get the current day −DateTime.TodayNow, add -1 to the AddDays() method to get the previous day −DateTime.Today.AddDays(-1)The following is the code −Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       Console.WriteLine("Today = {0}", DateTime.Today);       Console.WriteLine("Previous Day = {0}", DateTime.Today.AddDays(-1));    } }OutputToday = 9/4/2018 12:00:00 AM Previous Day = 9/3/2018 12:00:00 AM

Advertisements