Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
psdtohtml5 / gist:5842736
Created June 22, 2013 21:46
jQuery: Checkbox Change Event
$(".checkbox").change(function() {
if(this.checked) {
//Do stuff
}
});
@psdtohtml5
psdtohtml5 / gist:5743421
Created June 9, 2013 13:00
PHP: Prepare parameters for PDO Quries
<?php
/**
* This function loops through the $_POST global and returns parameters that can be used in
* a PDO statement directly. Note : For this function to work properly the
* PDO::ATTR_EMULATE_PREPARES should be set to "false"
* like so "$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false)".
* @param Array $exclude This is an array of keys in $_POST that you want the function to ignore
* @return Array The function returns an array that can be used as parameters for the PDO statement
*/
function get_params($exclude = array()) {
@psdtohtml5
psdtohtml5 / gist:5734835
Created June 8, 2013 11:04
PHP: Pagination
<?php
try {
$company = $conn->prepare('SELECT `id`, `name`, `name_lang2`, `is_active`, `sort_order` FROM `companies`' );
$company -> execute();
$count = $company->rowCount();
}
@psdtohtml5
psdtohtml5 / gist:5646820
Created May 24, 2013 22:04
PHP: PDO Prepared Statement
<?php
// PDO Prepared statements
try {
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM myTable WHERE id = :id');
$stmt->execute(array('id' => $id));
@psdtohtml5
psdtohtml5 / gist:5646814
Created May 24, 2013 22:04
PHP: PDO database connect
<?php
// Connect to database using PDO
try {
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
@psdtohtml5
psdtohtml5 / gist:5646810
Created May 24, 2013 22:03
PHP: Secure File Download
<?php
// PHP SECURE FILE DOWNLOAD
// Put the Files in a directory that is not publically accessible.. maybe outside document root or set correct permissions
if (!$_SESSION["authenticated"]) {
// If not authenticated then send back to the login page
$host = $_SERVER["HTTP_HOST"];
$path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
header("Location: http://$host$path/login.php?err=true");
exit;
@psdtohtml5
psdtohtml5 / gist:5553482
Created May 10, 2013 09:46
WordPress : Creating Meta Box Link
https://github.com/bainternet/My-Meta-Box
@psdtohtml5
psdtohtml5 / gist:5552934
Created May 10, 2013 07:28
WordPress : Getting All Categories
<?php
$args = array(
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
@psdtohtml5
psdtohtml5 / gist:5477621
Created April 28, 2013 17:28
jQuery : Multiple Videos In Lightbox
Multiple videos in Lightbox / Overlay
Dependencies:
http://releases.flowplayer.org/js/flowplayer-3.2.12.min.js
http://cdn.jquerytools.org/1.2.6/all/jquery.tools.min.js
The CSS
<style>
.overlay {
@psdtohtml5
psdtohtml5 / gist:5432566
Created April 22, 2013 05:11
HTML : Basic Form Structure
// Basic HTML Form
<form id="contact-form" class="span7 cf" action="" method="post">
<div id="status">
</div>
<legend>Leave us a message</legend>
<span class="col3 first">
<input type="text" id="name" name="name" placeholder="Name">
</span>