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
Author: Melvin
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}; […]
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 […]
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 […]
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: = = […]
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
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.
HTML Special Characters
– – – en dash — — — em dash ¡ ¡ ¡ inverted exclamation ¿ ¿ ¿ inverted question mark " " " quotation mark “ “ “ left double curly quote ” ” ” right double curly quote ' ' apostrophe (single quote) ‘ ‘ ‘ left single curly quote ’ ’ […]
Formatting money / currency using PHP
$formatted = number_format($number,2);
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