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: show_ordinal
function show_ordinal($num) {// first convert to string if needed
$the_num = (string) $num;
// now we grab the last digit of the number
$last_digit = substr($the_num, -1, 1);
// if the string is more than 2 chars long, we get
// the second to last character to evaluate
if (strlen($the_num)>1) {
$next_to_last = substr($the_num, -2, 1);
} else {
$next_to_last = "";
}
// now iterate through possibilities in a switch
switch($last_digit) {
case "1":
// testing the second from last digit here
switch($next_to_last) {
case "1":
$the_num.="th";
break;
default:
$the_num.="st";
}
break;
case "2":
// testing the second from last digit here
switch($next_to_last) {
case "1":
$the_num.="th";
break;
default:
$the_num.="nd";
}
break;
// if last digit is a 3
case "3":
// testing the second from last digit here
switch($next_to_last) {
case "1":
$the_num.="th";
break;
default:
$the_num.="rd";
}
break;
// for all the other numbers we use "th"
default:
$the_num.="th";
}
// finally, return our string with it's new suffix
return $the_num;
}
***Declared In:/home4/adamwith/public_html/includes/functions/fw_stringManipulation.php
Add a hyphen to lists when Copying & Pasting
const prependChar = "-"; document.addEventListener("copy", function(e) { const selected = getSelectionHtml(); if (selected.html.includes("
- ${html}