AmitDiwan has Published 10744 Articles

MySQL query to remove numbers after hyphen in a VARCHAR string with numbers

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:54:11

559 Views

For this, use SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable2040    -> (    -> StudentCode varchar(20)    -> ); Query OK, 0 rows affected (0.85 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2040 values('John-232'); Query OK, 1 row affected (0.13 ... Read More

Simplest way to detect client locale in PHP

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:52:30

1K+ Views

PHP provides a function beginning from 5.3.0 to parse the ‘$_SERVER['HTTP_ACCEPT_LANGUAGE']’ variable into a locale −Example$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); echo $locale;The ‘$_SERVER['HTTP_ACCEPT_LANGUAGE']’ function helps detect the locale by taking the current locale’s language as the parameter.OutputThis will produce the following output −en_USMost browsers submit an Accept-Language HTTP header that specifies en-us ... Read More

Displaying only a list of records in ASC order with MySQL

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:52:28

161 Views

To display a list of records in a specific order, you need to set conditions and use ORDER BY. For this, use ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable2039    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows ... Read More

MySQL query to return TRUE for rows having positive value?

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:51:39

273 Views

To return TRUE for positive values and FALSE for negative, use MySQL IF(). Let us first create a table −mysql> create table DemoTable2038    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Value int    -> ); Query OK, 0 rows affected (0.87 sec)Insert some ... Read More

Reading/Writing a MS Word file in PHP

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:50:09

650 Views

Microsoft strongly advises not to use the automation of Office documents via COM objects. It quotes the following −“Microsoft does not currently recommend or support the Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit ... Read More

PHP: recreate and display an image from binary data

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:48:20

2K+ Views

This can be done using data URI in the image src attribute.Formatdata:[][;charset=""][;base64],

URL Decoding in PHP

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:45:18

555 Views

URL decoding can be done using the built-in 'urldecode' function. This returns the encoded data.Syntax of urldecode functionstring urldecode($input)It takes a single parameter ($input) which is the URL that is to be decoded. Returns the decoded string provided the decoding was successful −Example Live Demo In the above lines of the code, the ... Read More

Convert ASCII TO UTF-8 Encoding in PHP?

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:43:58

8K+ Views

If we know that the current encoding is ASCII, the 'iconv' function can be used to convert ASCII to UTF-8. The original string can be passed as a parameter to the iconv function to encode it to UTF-8.Example Live DemoA string with special characters is assigned to ‘str’ variable. This is ... Read More

Fetch the first letter of a column value and insert it in another column with MySQL

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:41:05

457 Views

For this, use the concept of LEFT() function. Let us first create a table −mysql> create table DemoTable2036    -> (    -> FirstLetter varchar(20),    -> Title varchar(20)    -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

Download file through an AJAX call in PHP

AmitDiwan

AmitDiwan

Updated on 07-Apr-2020 11:40:45

2K+ Views

Using Ajax to download files is not considered to be a good idea. Instead, window.location = or document.location should be used.The 'window.location' has the following characteristics −JavaScript enabling is requiredIt doesn't need PHP.It helps show the content of the site, and redirects the user after a few seconds.Redirect can be ... Read More

Advertisements