We can use the SQL UPDATE command with or without the WHERE CLAUSE in the PHP function – mysql_query(). This function will execute the SQL command in a similar way it is executed at the mysql> prompt. To illustrate it we are having the following example −ExampleIn this example, we are writing a PHP script to update the field named tutorial_title for a record having turorial_id as 3.
Get the location of array elements using the BinarySearch method.Set a string array −string[] str = { "a", "m", "i", "t"};Now get the location of character ‘t’ using Array.BinarySearch −Array.BinarySearch(str, "t");Here is the complete code −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { string[] str = { "a", "m", "i", "t"}; // Using BinarySearch method to get location of character 't' int res = Array.BinarySearch(str, "t"); // displaying the location Console.WriteLine("Index : "+res); } }OutputIndex : 3
As we know that MySQL BETWEEN operator can be used to select values from some range of values. We can use BETWEEN operator along with views to select some range of values from the base table. To understand this concept we are using the base table ‘student_info’ having the following data −mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla ... Read More
Use the ConvertAll method to convert integer array to string array.Set an integer array −int[] intArray = new int[5]; // Integer array with 5 elements intArray[0] = 15; intArray[1] = 30; intArray[2] = 44; intArray[3] = 50; intArray[4] = 66;Now use Array.ConvertAll() method to convert integer array to string array −Array.ConvertAll(intArray, ele => ele.ToString());Let us see the complete code −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { int[] intArray = new int[5]; // Integer array with 5 elements intArray[0] = 15; intArray[1] = 30; intArray[2] = 44; intArray[3] = 50; intArray[4] = 66; string[] strArray = Array.ConvertAll(intArray, ele => ele.ToString()); Console.WriteLine(string.Join("|", strArray)); } }Output15|30|44|50|66
Use the Array.Exists method to check if a value is in an array or not.Set a string array −string[] strArray = new string[] {"keyboard", "screen", "mouse", "charger" };Let’s say you need to find the value “keyboard” in the array. For that, use Array.Exists() −Array.Exists(strArray, ele => ele == "keyboard");It returns a true value if element exists as shown below −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { string[] strArray = new string[] {"keyboard", "screen", "mouse", "charger" }; bool res1 = Array.Exists(strArray, ele => ele == "harddisk"); ... Read More
To find the last matching element, use the Array.LastIndexOf method. Returns -1 if the element isn’t present in the integer array.The following is the array −int[] val = { 97, 45, 76, 21, 89, 45 };Now, let’s say you need to search the last Index of element 45. For that, use Array.LastIndexOf() method −int res = Array.LastIndexOf(val, 45);The following is an example −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { int[] val = { 97, 45, 76, 21, 89, 45 }; // last Index of element 45 int res = Array.LastIndexOf(val, 45); // Display the index Console.WriteLine("Index of element 45 is = "+res); } }OutputIndex of element 45 is = 5
With TrueForAll() method in arrays, you can check every element for a condition.Let us see an example −Example Live Demousing System; using System.Text; public class Demo { public static void Main() { int[] val = { 97, 45, 76, 21, 89, 45 }; // checking whether all the array element are more than one or not bool result = Array.TrueForAll(val, res => res > 1); Console.WriteLine(result); } }OutputTrueWith TrueForAll() method in arrays, you can check every element for a condition.Let us see an example −Example Live Demousing System; ... Read More
Firstly, set a list −List myList = new List(); myList.Add(45); myList.Add(77);Now, to clear the above list, use Clear() −myList.Clear();Here is the complete code −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { List myList = new List(); myList.Add(45); myList.Add(77); Console.WriteLine("Elements: "+myList.Count); myList.Clear(); Console.WriteLine("Elements after using clear: "+myList.Count); } }OutputElements: 2 Elements after using clear: 0
Set an array −int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70;Now set a list and add array in it −List myList = new List(val);The following is the code −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70; List myList = new List(val); Console.WriteLine("Elements..."); foreach(int res in myList) { Console.WriteLine(res); } // count integer elements Console.WriteLine("Number of elements: "+myList.Count); } }OutputElements... 15 25 40 58 70 Number of elements: 5
To illustrate this we are fetching all the records from a table named ‘Tutorials_tbl’ with the help of PHP script that uses mysql_fetch_assoc() function in the following example −Example
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP