SQL Coding Standards
A Sample of My Coding Functions, for Quick Reference.Updated 1 year ago
Coding and Naming Standards:
On every project I've worked on, people have discussed coding & Naming Standards, but we always eventually realize that nobody has written these things down. So I have started these proposed standards:
- Names: like_this
- ID: Must be (INT) Named like: table_id
Coding Analogies
- Variable- Cooking ingredient
- Switch - Train switching station. or a choose your own adventure
- If - For in the road
- Break - Exit out of current Loop
- Exit (or Die)- Quit IMMEDIATELY, and print something to the screen
Regex GEdit:
Delete every other line.([^\n]*\n)[^\n]*\n\1
Regex tester for Search AND Replace:
RegExe.comMake all Links open in a New Window jquery.
<script>$("#content a[href^='http://']").attr("target","_blank");</script><script>$("#content a[href^='https://']").attr("target","_blank");</script>
SQL Queries
Count all Table Rows
SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = "adamwith_main";Hwo to assign an array to two variables
I always forget :Plist($first, $second)=array(1,2);
Geo IP Location:
You are in: Columbus, United StatesMy Commonly Used Functions:
View Function: geturlpath
function getUrlPath(){//the full address from the browser
$hostName = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$url = 'https://'.$hostName.$_SERVER['REQUEST_URI'];
//here we are going to get the entire path after the domain/subdomain
if(isset($_SERVER['REDIRECT_URL']) ){
//echo 'condition 1';
$request = parse_url($_SERVER['REDIRECT_URL']);
}elseif(isset($_SERVER['REDIRECT_URI']) ){
//echo 'condition 2';
$request = parse_url($_SERVER['REDIRECT_URI']);
}else{
//echo 'condition 3';
$request =array('path'=>'index.php');
}
//print_r($request);
//$request = parse_url($_SERVER['REDIRECT_URL']);//fixed, I think Apr 15, 2021
$request= ltrim ($request['path'],'');
//print_r($request);
//die($request);
//now we are going to parse out the actual domain info
$info = parse_url($url);
$host = $info['host'];
$host_names = explode(".", $host);
//preset the domainRoot will be overwritten if we are in a subdomain
$domainRoot = $hostName;
//now we are setting subdomain variable and parsed array for loading content
if(count($host_names) > 2){
$subdomain = $host_names[0];
$domainRoot = null;
for($i=1; $i < (count($host_names)); $i++){
if($i === count($host_names)-1){
$sep = '';
}else{
$sep = '.';
}
$domainRoot .= $host_names[$i].$sep;
}
}else{
$subdomain = null;
}
//set some on the fly variables for the global variables
$subfolder = ltrim(str_replace($_SERVER['DOCUMENT_ROOT'],'',__FILE_ROOT__) ,'/');
$siteRoot = 'https://'.$domainRoot.$subfolder;//Changed by Adam from http to https
$domainRoot = ltrim($domainRoot, '.');
//set a global for use in post and functions
define('__SUB_DOMAIN__', $subdomain);
define('__SITE_ROOT__', $siteRoot);
define('__DOMAIN__', $domainRoot);
define('__REQUEST__', $request);
define('__SUBFOLDER__', $subfolder);
define('__CURRENT__', 'https://'.$subdomain.'.'.$domainRoot);
}
***Declared In:/home4/adamwith/public_html/includes/functions/fw_miscUniversal.php
Add a hyphen to lists when Copying & Pasting
const prependChar = "-"; document.addEventListener("copy", function(e) { const selected = getSelectionHtml(); if (selected.html.includes("
- ${html}