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: getthumbnailpicsin
function getThumbnailPicsIn($folder,$matching=null,$nameToShow='',$style=null,
$width=200,$height=null,
$likes=false,$class='',$zoom=false,
$exceptFor=array(),$maxRow=null,$reportIfNoImages=true,$link=null,$clear=true
//getThumbnailPicsIn('/themes/public/images/memes/','conspiracy',$nameToShow=true,$style='float:left;',$width=192,$height=null,$likes=false,$class='',$zoom=true)
){
if($style===null||$style===false){
$style='border:blue solid 2px;text-align:center;float:left;';//DONT SET background-color:blue; because it will show even if no title.
//$style='border:blue solid 2px;background-color:blue;text-align:center;overflow:hidden;';
}
//echo 'getThumbnailPicsIn('.$folder.',width='.$width.')
';
//prettyArray($exceptFor);
//prettyArray($GLOBALS['picsListed']);
$toReturn='';
$foundPics=0;
//die( 'Showing Thumbnails in "'.$folder.'" that match: "'.$matching.'"
$nameToShow='.var_export($nameToShow,true).'
CMD:'.getcwd() );
if( ! file_exists($_SERVER['DOCUMENT_ROOT'].'/'.$folder) ){
return 'Error 1234sdfn2x: Directory doe not exist: '.$_SERVER['DOCUMENT_ROOT'].'/'.$folder.'
';
}
$fileInFolder=scandir($_SERVER['DOCUMENT_ROOT'].'/'.$folder);
if($fileInFolder == false){
return 'Error 1234sdfn4x: No Files in Folder: '.$_SERVER['DOCUMENT_ROOT'].'/'.$folder.'
';
}
foreach($fileInFolder as $eachFile) {
if(substr($folder,0,1)=='/'){
$folder=substr($folder,1);//cut off starting ../
}
if($exceptFor!=null && is_array($exceptFor) && count($exceptFor)>0 ){
/*echo 'Debug: Is: '.removefileextension($eachFile).
' INNNNNNNN: '.implode(',',$exceptFor).
' ( '.var_export($exceptFor,true).')'.
'==='.var_export(in_array(removefileextension($eachFile),$exceptFor),true).'
';
*/
}
if(gettype($exceptFor) !=='array'){
$exceptFor=array();
}
if(in_array(removefileextension($eachFile),$exceptFor) ){
//DO NOthing
//$toReturn.= 'Debug getThumbnailPicsIn- Exmpetion: '.$eachFile.'
';
}else if ( $eachFile != "." && $eachFile != ".." && ! is_dir($folder.$eachFile)) {
$multiHit=false;
if( is_array($matching) ){
foreach($matching as $eachMatching){
//$toReturn.= 'CHECKING '.$eachFile.' for '.$eachMatching.'
';
if(stripos($eachFile,$eachMatching)!==false){
//$toReturn.= 'FOUND '.$eachMatching.'
';
$multiHit=true;
//$matching=$eachMatching;
}
}
//die('#Error 2452234234: getThumbnailPicsIn() is passed an array, instead of a $matching string.
'.var_export($matching,true));
}
if($matching==null || (is_string($matching) && strpos($eachFile,$matching)!==false) || $multiHit===true){
//$toReturn.='YES. "'.$eachFile.'" does match on: "'.$matching.'"
';
if(in_array(getFileExtension($eachFile),$GLOBALS['pictureFileExtentions'] ) ){
if($nameToShow==null){
//$toReturn.='fffffff';
$filePrettyName='';
}else if($nameToShow!=''&&$nameToShow!==true){
//$toReturn.='hhhhhhhh';
$filePrettyName=$nameToShow;
}else{
//$toReturn.='gggggggggg'.$eachFile;
$filePrettyName=cleanfortitle(
str_replace(
$matching,'',removefileextension($eachFile)
)
);
}
//$toReturn.='gggggggggg'.$filePrettyName;
if(isset($GLOBALS['picsListed'][$eachFile]) ){
//echo('Breaking on: '.$eachFile.'
');
continue;
}
$GLOBALS['picsListed'][$eachFile]=1;
$possibleThumb=thumbnailExists('./'.$folder.''.$eachFile,$width,$height,$zoom);
if( ! $possibleThumb && $style==''){
$style.=';background-color:orange;';
}
$divEachPic='
';
if(! isset($GLOBALS['countFacebookLikes']) ){
//return 'Error: You must declare $facebook to use the "Like" Feature.';
$GLOBALS['countFacebookLikes']=1;
}
if($likes===true){
$divEachPic.='[@facebookLike'.$GLOBALS['countFacebookLikes']++.']';
}
if(substr($folder,0,3)=='../'){
$folder=substr($folder,3);//cut off starting ../
}
$imgClass='';
if($maxRow!==null && $width='100%'){
$width=200;
$imgClass='fitTight';
}
if($link==null || $link==true){
$link='/'.$folder.''.$eachFile.'';
}
if(getFileExtension($eachFile)=='gif'){
$divEachPic.=''.
'';
}else{
//$divEachPic.=''.
$filePrettyName=str_replace('ë','ë',str_replace('"','"',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',$filePrettyName)))));
$link=str_replace('ë','ë',str_replace('"','"',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',$link)))));
$eachFile=str_replace('ë','ë',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',str_replace('"','"',str_replace('&','-AMP-',$eachFile))))));
if( $possibleThumb ){
$possibleThumb=str_replace('ë','ë',str_replace('"','"',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',$possibleThumb)))));
$divEachPic.='';
}else{
$pic='/includes/thumb.php?file=/'.$folder.''.$eachFile.($width?'&width='.$width:'').($height?'&height='.$height:'').($zoom?'&zoom=true':'').'';
$divEachPic.='';
}
//$divEachPic.='';
}
if($filePrettyName!=''){
$divEachPic.='
}
$divEachPic.='
';
if(! isset($GLOBALS['countFacebookLikes']) ){
//return 'Error: You must declare $facebook to use the "Like" Feature.';
$GLOBALS['countFacebookLikes']=1;
}
if($likes===true){
$divEachPic.='[@facebookLike'.$GLOBALS['countFacebookLikes']++.']';
}
if(substr($folder,0,3)=='../'){
$folder=substr($folder,3);//cut off starting ../
}
$imgClass='';
if($maxRow!==null && $width='100%'){
$width=200;
$imgClass='fitTight';
}
if($link==null || $link==true){
$link='/'.$folder.''.$eachFile.'';
}
if(getFileExtension($eachFile)=='gif'){
$divEachPic.=''.
'';
}else{
//$divEachPic.=''.
$filePrettyName=str_replace('ë','ë',str_replace('"','"',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',$filePrettyName)))));
$link=str_replace('ë','ë',str_replace('"','"',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',$link)))));
$eachFile=str_replace('ë','ë',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',str_replace('"','"',str_replace('&','-AMP-',$eachFile))))));
if( $possibleThumb ){
$possibleThumb=str_replace('ë','ë',str_replace('"','"',str_replace('+','%2b',str_replace('é','é',str_replace('ö','ö',$possibleThumb)))));
$divEachPic.='';
}else{
$pic='/includes/thumb.php?file=/'.$folder.''.$eachFile.($width?'&width='.$width:'').($height?'&height='.$height:'').($zoom?'&zoom=true':'').'';
$divEachPic.='';
}
//$divEachPic.='';
}
if($filePrettyName!=''){
$divEachPic.='
'.$filePrettyName.'
'."\n";//
}
$divEachPic.='
//echo $foundPics.'%'.$maxRow.'=='.($foundPics%$maxRow).'
';
$toReturn.=$divEachPic;
if($maxRow!=null && ($foundPics%$maxRow)==0){
}
$foundPics++;
}
}else{
//echo('NO. "'.$eachFile.'" does NOT match on: "'.$matching.'"
');
}
//echo $eachFile.'
';
}
}
if($maxRow!==null){
}
//echo('foundPics='.$foundPics. ' for "'.$matching.'"
'."\n");
if($foundPics>1 && $clear==true){$toReturn.='';}
if($foundPics<=0 && $reportIfNoImages===true){
$toReturn.= '
'.
''title="Error '.$foundPics.' Pics Found matching \''.$matching.'\' in \''.$folder.'">'.
'
'
';
''title="Error '.$foundPics.' Pics Found matching \''.$matching.'\' in \''.$folder.'">'.
'
'.$matching.'
'.
'
}
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}