Creating An Array Of All Results $all_results = array(); //Empty array to hold returned rows while ($row = @mysql_fetch_array($search_query)) { $all_results[] = $row; }
All posts by
Time Difference
Seconds Since DateTime
DateTime general
ORDER BY Date Order ASC = oldest first DESC = most recent first Note it’s “MINUTE”, “HOUR”, etc not “MINUTES” or “HOURS” etc Convert DateTime to Date Specifying Date and DateTime from a string It is recommended to use CAST() Last Day Of Month (This produces a DATE result, not DATETIME) Get SQL Server’s Current […]
Getting Site URL
See also: /php/page-control/get-page-uri-url Getting Site URL
TextArea
Note – for single line test use <input type=”text” not textarea! Max length Background text Text that vanished when you start typing into the box
Referencing Site Root
include_once ($_SERVER[‘DOCUMENT_ROOT’] . '/lang/english.php');
Global Variables & Defines
Variables Any variable used inside a function is by default limited to the local function scope. If you want to access a variable used outside of the function you need to declare it as global within the function: Defines No need to declare a define as global in functions, any function can simply use it
Returning Multiple Values
Return an array function my_function() { return array (0, 1, 2); } list ($value0, $value1, $value2) = my_function();
Using Strings-Formatting
Text Formatting Trim leading and trailing whitespace Capitalise 1st letter of first word Capitalise 1st letter of every word (but leave capitalised words like “ABC” as they are) String to lowercase String to uppercase Convert \n character to <br> when displaying as normal php text
Detecting Name Of Page Include A File
//include_once('includes/my_include_file.php'); //Get the name of the file calling this include $calling_file = end(explode('/', $_SERVER[‘PHP_SELF’])); switch ($calling_file) { case 'some_file.php':