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: buildwherestatement
function buildWhereStatement($array, $additional = null, $unix = false){
$wherea = array();
$where = null;
$start = null;
$end = null;
foreach ($array AS $key => $val) {
switch ($key) {
case 'dateRange':
if (!empty($_GET['start']) && !empty($_GET['end'])) {
if ($unix === false) {
$start = $_GET['start'];
$end = $_GET['end'];
} else {
$start = strtotime($_GET['start']);
$end = strtotime($_GET['end']);
}
$wherea[] = $array['dateRange'] . " BETWEEN '" . $start . "' AND '" . $end . "'";
}
break;
case 'name':
if (!empty($_GET[$key]) && $key !== 'dateRange') {
$wherea[] = " $val LIKE '%" . $_GET[$key] . "%'";
}
break;
default:
if (!empty($_GET[$key]) && $key !== 'dateRange') {
$wherea[] = " $val = '" . $_GET[$key] . "'";
}
break;
}
}
if (count($wherea) > 0) {
$count = 1;
$where .= " WHERE (";
if ($additional !== null) {
$where .= $additional . ' AND ';
}
foreach ($wherea AS $key => $val) {
if ($count < count($wherea)) {
$sep = ' AND ';
} else {
$sep = '';
}
$where .= $val . $sep;
$count++;
}
$where .= ")";
//prettyArray($wherea);
//echo $where;
} elseif (count($wherea) === 0 && $additional !== null) {
$where .= " WHERE (";
$where .= $additional;
$where .= ")";
}
return $where;
}
***Declared In:/home4/adamwith/public_html/includes/functions/fw_sqlQueries.php
Add a hyphen to lists when Copying & Pasting
const prependChar = "-"; document.addEventListener("copy", function(e) { const selected = getSelectionHtml(); if (selected.html.includes("
- ${html}