Skip to content

Instantly share code, notes, and snippets.

@snowbob
snowbob / mysql:count2tables
Created July 17, 2015 13:12
mysql count 2 table
SELECT co.*,
COALESCE(mod.moduleCount,0) AS moduleCount,
COALESCE(vid.vidCount,0) AS vidCount
FROM courses AS co
LEFT JOIN (
SELECT COUNT(*) AS moduleCount, course_id AS courseId
FROM modules
GROUP BY course_id
) AS mod
ON mod.courseId = co.id
@snowbob
snowbob / js:resize-frame
Created July 6, 2015 09:11
resize iframe with timer
endAndStartTimer();
var timer;
function endAndStartTimer() {
window.clearTimeout(timer);
//var millisecBeforeRedirect = 10000;
timer = window.setTimeout(function(){
resize_iframe();
},500);
}
@snowbob
snowbob / php: extrawhitespace
Created June 20, 2015 12:13
remove extra white spaces
$foo = trim(preg_replace( '/\s+/', ' ', $foo ));
@snowbob
snowbob / cdn
Created May 28, 2015 08:00
js:cdn
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
@snowbob
snowbob / php:incluededfiles
Created May 27, 2015 11:58
includedfiles
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filename\n";
}
@snowbob
snowbob / php:ajaxPage
Last active August 29, 2015 14:21
ajaxPage
<?php
include('../../../connect.php');
$id = (isset($_POST['id']) && $_POST['id'] != '') ? mysql_real_escape_string($_POST['id']) : '';
$value = (isset($_POST['value']) && $_POST['value'] != '') ? mysql_real_escape_string($_POST['value']) : '';
$ERROR=0;
@snowbob
snowbob / php: delete
Created May 10, 2015 12:16
php: delete
mysql_query("DELETE FROM example WHERE age='15'")or die(mysql_error());
@snowbob
snowbob / php: updatedb
Created May 10, 2015 12:09
php: updatedb
$table="|";
$sql="update from $table set = , = where id=$id";
$result=mysql_query($sql) or die ("<h3>Error</h3><p><b>".mysql_error()."</b></p>");
@snowbob
snowbob / php:insertdb
Created May 10, 2015 12:06
PHP: insertdb
$sql="insert into table () values ( , , , ) where id='$id'";
$result=mysql_query($sql) or die ("<h3>Error</h3><p><b>".mysql_error()."</b></p>");
@snowbob
snowbob / js:ajaxpost
Created April 26, 2015 15:53
js: simple ajaxpost
$.ajax({
url: 'ajaxCalls/remove_printer.php',
type: 'POST',
data: {
'id': id
},
dataType:"json",
success: function(response) {
if(response.status === "success") {