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: makecollage
function makeCollage($arr,$selectedCollage='NOTSPECIFIED'){// die('makeCollage ::
'.prettyArrayReturn($arr) );
include_once('./includes/siteRipper.php');
if( isset($arr['directory'])){
if( is_array($arr['directory']) ){
foreach($arr['directory'] as $eachDirectory){
if((! file_exists('.'.$eachDirectory)) ){echo('Error 3241r2222: One of the Collage Directories is not Found: '.$eachDirectory.'
');}
}
$arr['otherDirectory']=$arr['directory'][1];
$arr['directory']=$arr['directory'][0];
}else{
if((! file_exists('.'.$arr['directory'])) ){echo('Error 42342b1142: Collage Directory not Found: '.$arr['directory'].'
');}
}
}
$toReturn='
';
if (isset($arr['title']) ){
$toReturn.=''.$arr['title'].'
'."\n";
}
if (isset($arr['description']) ){
$toReturn.=''.$arr['description'].'
'."\n";
}
if (! is_array($arr) ){
return'
}
if(isset($_GET['answers'])&&$_GET['answers']=='true'){
$arr['picTitles']='filename';
//echo 'Showing Answers: '.$_GET['answers'].'
';
}
if(isset($arr['colsOrWidth']) && $arr['colsOrWidth']=='original'){
$fontSize=isset($arr['fontSize'])?$arr['fontSize']:0;
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&($arr['colsOrWidth']>13)&&isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){//The provided both colsOrWidth and fontSize
$eachWidthofPic=$arr['colsOrWidth'];
if($arr['colsOrWidth']>200){
$fontSize=19;
}else{
$fontSize=14;
}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==13){$eachWidthofPic=60;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=6;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==12){$eachWidthofPic=65;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=6;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==11){$eachWidthofPic=78;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=6;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==10){$eachWidthofPic=90;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=7;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==9){$eachWidthofPic=1000;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=8;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==8){$eachWidthofPic=110;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=9;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==7){$eachWidthofPic=120;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=10;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==6){$eachWidthofPic=133;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=11;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==5){$eachWidthofPic=160;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=12;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==4){$eachWidthofPic=210;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=14;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==3){$eachWidthofPic=280;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=17;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==2){$eachWidthofPic=426;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=18;}
}else{$eachWidthofPic=390;$fontSize=18;}//426 x 213
$arrNoImage=array();//Images in the Array, that we can't find in the Directory
$newDeaths=array();//if checkNewDeaths we will write these.
if (isset($arr['random'])&&$arr['random']===true ){
$arr=shuffleAssoc($arr);
}
$i=1;
$iRow=0;
$debugPrintOut='
';
return $toReturn;
}
***Declared In:/home4/adamwith/public_html/includes/functions/adamwithers.ca.php
if (isset($arr['title']) ){
$toReturn.=''.$arr['title'].'
'."\n";
}
if (isset($arr['description']) ){
$toReturn.=''.$arr['description'].'
'."\n";
}
if (! is_array($arr) ){
return'
Error: Not an Array.
';}
if(isset($_GET['answers'])&&$_GET['answers']=='true'){
$arr['picTitles']='filename';
//echo 'Showing Answers: '.$_GET['answers'].'
';
}
if(isset($arr['colsOrWidth']) && $arr['colsOrWidth']=='original'){
$fontSize=isset($arr['fontSize'])?$arr['fontSize']:0;
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&($arr['colsOrWidth']>13)&&isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){//The provided both colsOrWidth and fontSize
$eachWidthofPic=$arr['colsOrWidth'];
if($arr['colsOrWidth']>200){
$fontSize=19;
}else{
$fontSize=14;
}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==13){$eachWidthofPic=60;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=6;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==12){$eachWidthofPic=65;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=6;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==11){$eachWidthofPic=78;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=6;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==10){$eachWidthofPic=90;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=7;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==9){$eachWidthofPic=1000;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=8;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==8){$eachWidthofPic=110;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=9;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==7){$eachWidthofPic=120;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=10;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==6){$eachWidthofPic=133;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=11;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==5){$eachWidthofPic=160;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=12;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==4){$eachWidthofPic=210;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=14;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==3){$eachWidthofPic=280;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=17;}
}else if(isset($arr['colsOrWidth'])&&is_numeric($arr['colsOrWidth'])&&$arr['colsOrWidth']==2){$eachWidthofPic=426;if(isset($arr['fontSize'])&&is_numeric($arr['fontSize']) ){$fontSize=$arr['fontSize'];}else{$fontSize=18;}
}else{$eachWidthofPic=390;$fontSize=18;}//426 x 213
$arrNoImage=array();//Images in the Array, that we can't find in the Directory
$newDeaths=array();//if checkNewDeaths we will write these.
if (isset($arr['random'])&&$arr['random']===true ){
$arr=shuffleAssoc($arr);
}
$i=1;
$iRow=0;
$debugPrintOut='
eachPic | eachHeading | potentialPicFile | potentialOtherFile | Death Date | ||
---|---|---|---|---|---|---|
Newline: '.$eachPic.' | ||||||
'.$eachPic.' | '.'.prettyArrayReturn($eachHeading).' | '.'. $potentialPicFile.' | '.'.(isset($potentialOtherFile)?$potentialOtherFile:'NULL').' | '.'.$deathDate.' |
return $toReturn;
}
***Declared In:/home4/adamwith/public_html/includes/functions/adamwithers.ca.php
Add a hyphen to lists when Copying & Pasting
const prependChar = "-"; document.addEventListener("copy", function(e) { const selected = getSelectionHtml(); if (selected.html.includes("
- ${html}