Skip to content

Instantly share code, notes, and snippets.

<?php
class DoMath {
public $var;
public static $boo;
public function addToVar($value) {
// $this->var += $value;
}
@bbatsche
bbatsche / snippet.php
Last active August 29, 2015 13:56
Snippet on how to reset the array keys
<?php
// ...
} elseif ($input == 'R') {
// Remove which item?
echo 'Enter item number to remove: ';
// Get array key
$key = trim(fgets(STDIN));
while ($key < count($items)) {
$items[$key - 1] = $items[$key];
@bbatsche
bbatsche / pdo-example.php
Last active August 29, 2015 13:57
Examples of PDO Calls
<?php
/*******************************
* Setup Connection
*******************************/
$dbc = new PDO('mysql:host=127.0.0.1;dbname=codeup_demo_db', 'username', 'password');
// Tell PDO to throw exceptions on error
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@bbatsche
bbatsche / User Role Example.sql
Created March 18, 2014 22:58
An example of how to create a table relating a user table and a role table and an example of how to join across the two.
CREATE TABLE user_role (
user_id INT(10) UNSIGNED NOT NULL,
role_id INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (user_id, role_id),
CONSTRAINT user_role_role_fk FOREIGN KEY (role_id) REFERENCES role (id)
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT user_role_user_fk FOREIGN KEY (user_id) REFERENCES `user` (id)
ON DELETE CASCADE ON UPDATE CASCADE
);
@bbatsche
bbatsche / Vagrantfile
Created May 6, 2014 20:49
Badlands Config Suppliment
# -*- mode: ruby -*-
# vi: set ft=ruby :
#############################
# Codeup Server Setup
#############################
box = 'chef/ubuntu-14.04'
hostname = 'codeup-trusty'
domain = 'codeup.dev'
@bbatsche
bbatsche / multi.php
Created May 16, 2014 14:06
Multimeter Lottery
<?php
$students = array(
'Andrew',
'Caitlin',
'Josue',
'Genaro',
'Amanda',
'Ashley F',
'Michael',
@bbatsche
bbatsche / files.php
Created May 21, 2014 16:21
PHP File Handling Notes
<?php
/************************************
* NOTE!!!!
* This file is meant as notes / examples.
* The code, as it's current written, will not work
* and will probably output some errors/notices.
* Use this file as examples, not as code that's meant to be run.
************************************
*/
@bbatsche
bbatsche / todo_init.php
Created August 19, 2014 21:00
Todo List Sorting
<?php
$items = [
0 => 'first',
1 => 'second',
2 => 'third'
];
// A
@bbatsche
bbatsche / stopwatch.html
Created September 4, 2014 21:00
A JavaScript stop watch, demonstrating the use of events, intervals, and querying the DOM
<!DOCTYPE html>
<html>
<head>
<title>Stop Watch</title>
</head>
<body>
<h1>Stop Watch</h1>
<button id="startButton">Start</button>
<button id="stopButton">Stop</button>
@bbatsche
bbatsche / remove.php
Last active December 11, 2015 21:06
Example of how to use JavaScript and a form to send a request using POST, rather than anchor tags and GET requests.
<?php foreach: ($parks as $parkInfo): ?>
<!-- ... -->
<td>
<!-- This is the button the user will click to remove an item -->
<button class="btn btn-danger btn-xs btn-delete" data-id="<?= $parkInfo['id']; ?>" data-name="<?= $parkInfo['name']; ?>">
Delete
</button>
</td>