Categories
SQL

Insert data from one table to another table

INSERT INTO “table1” (“column1”, “column2”, …) SELECT “column3”, “column4”, … FROM “table2” INSERT INTO Store_Information (store_name, Sales, Date) SELECT store_name, Sales, Date FROM Sales_Information WHERE Year(Date) = 1998

Categories
PHP

Using substr()

<?php print substr(‘abcdef’, 1); // bcdef print substr(‘abcdef’, 1, 3); // bcd print substr(‘abcdef’, 0, 4); // abcd print substr(‘abcdef’, 0, 8 ); // abcdef print substr(‘abcdef’, -1, 1); // f // Accessing single characters in a string // can also be achived using “curly braces” $string = ‘abcdef’; print $string{0}; // a print $string{3}; […]

Categories
ASP

String Functions (Len, Left, Right, Mid)

<% dim myvar myvar = “1234567” response.Write(myvar & ” is the variable<br/>”) response.Write(len(myvar) & ” characters long<br/>”) response.Write(left(myvar,3) & ” are the <b>left</b> three characters<br/>”) response.Write(right(myvar,3) & ” are the <b>right</b> three characters<br/>”) response.Write(mid(myvar,3,3) & ” : Mid(MyString, StartPos, NumChars)<br/> %> Output: 1234567 is the variable 7 characters long 123 are the left three characters […]

Categories
ASP

ASP: Find the length of a string using len and lenB function

my_string=”Welcome to MySite.com” Response.Write ( my_string ) Response.Write “Length of this string = ” & len(my_string) Response.Write “Number of bytes Required for this string = ” & lenB(my_string) The output of this will also show the number of bytes required. Here in this case it will print this: Welcome to MySite.com Length of this string […]

Categories
PHP

PHP: Expressions and Operators

Arithmetic Operators: + Addition Add two values – Subtraction Subtract the second value from the first * Multiplication Multiply two values / Division Divide the first value by the second % Modulus Divide the first value by the second and return only the remainder (for example, 7 % 5 yields 2) Comparison Operators: = = […]

Categories
SQL

SQL Select leftmost or rightmost characters from rows of data

SELECT left(item_num, 4) FROM flowers; If item_num = 754861 then the output will be: 7548 SELECT right(item_num, 4) FROM flowers; If item_num = 754861 then the output will be: 4861

Categories
PHP

eregi_replace() vs. ereg_replace()

Code: <?php $s = “Coding PHP is fun.”; print “ereg_replace(): ” . ereg_replace(“CODING”, “Learning”, $s) . “<br>”; print “eregi_replace(): ” . eregi_replace(“CODING”, “Learning”, $s); ?> Output: ereg_replace(): Coding PHP is fun. eregi_replace(): Learning PHP is fun. Explanation: eregi_replace() is case insensitive, while ereg_replace() is not.

Categories
HTML

HTML Special Characters

– &ndash; &#8211; en dash — &mdash; &#8212; em dash ¡ &iexcl; &#161; inverted exclamation ¿ &iquest; &#191; inverted question mark " &quot; &#34; quotation mark “ &ldquo; &#8220; left double curly quote ” &rdquo; &#8221; right double curly quote '   &#39; apostrophe (single quote) ‘ &lsquo; &#8216; left single curly quote ’ &rsquo; […]

Categories
PHP

Formatting money / currency using PHP

$formatted = number_format($number,2);

Categories
PHP

PHP basename() Function

The basename() function returns the filename from a path. <?php $path = “/mywebsite/home.php”; //Show filename with file extension echo basename($path) .”<br/>”; //Show filename without file extension echo basename($path,”.php”); ?> The output of the code above will be: home.php home