Created by Sal Testa and Andrew Capshaw
<!DOCTYPE html>
<html>
<head>
<title>HackRice 2013 Project</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HackRice 2013 Project</title>
...
<link href="css/bootstrap.css" rel="stylesheet">
</head>
<body>
...
<script src="http://code.jquery.com/jquery.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>
<div id="welcome-text">Welcome!</div>
<div class="container">
<button class="button button-red" id="cancel">No</button>
<button class="button button-blue" id="accept">Yes</button>
<button class="button button-yellow" id="not-sure">Maybe</button>
</div>
Ids and classes are used by css and javascript to reference specific indvidual or groups of elements.
body {width: 500px;}
.tag-class {
padding: 20px 40px;
width: auto;
}
#tag-id {
height: 100px;
float: left;
}
Notice that "#" delimites an id and "." a class.
.tag-class {
padding-top: 40px;
width: auto;
}
function biggest (numbers) {
var current = numbers[0];
for (var i = 0; i < numbers.length; i++) {
if (numbers[i] > current) {
current = numbers[i];
}
};
return current;
}
/* Run when the document is finished loading. */
$(document).ready(function() {
$("#messageButton").click(function() {
var name = $("#name").val();
alert("Hello "+name+", it's nice to meet you!");
}
});
function storeName(userName) {
$.ajax({
url:'./process_name.php', // destination
type:'POST', // sending via POST or GET
data: {
'name':userName
}
});
}
function storeName(userName) {
$.ajax({
url:'./process_name.php',
type:'POST',
data: {
'name':userName
}
}).done(function(data){
var response = JSON.parse(data); // makes a map out of the data
if(response['status'] == 'success') {
alert("Everything is dandy!");
} else {
alert("Today is a dark day indeed!");
}
});
}
<?php
function biggest($numbers) {
$current = $numbers[0];
for ($i=0; $i < count($numbers); $i++) {
if(numbers[$i] > $current) {
$current = numbers[$i];
}
}
return $current;
}
?>
<?php /* config.php */
define( 'DB_HOST', 'localhost' );
define( 'DB_DATABASE', 'hackrice' );
define( 'DB_USER', 'root' );
define( 'DB_PASSWORD', 'password' );
?>
<?php /* other_thing.php */
require_once( 'config.php' );
...
?>
<?php
function get_user_by_id($uid) {
$DB = new mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE );
$query = 'SELECT name FROM users WHERE uid = "'.$uid.'"';
$result = $DB->query($query);
$row = $result->fetch_assoc();
return $row['name'];
}
?>
<?php
/* process_name.php */
$name = $_POST['name'];
$DB = new mysqli( DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE );
$query = 'INSERT INTO users VALUES "'.$name.'"';
$DB->query($query);
$response = array();
$response['status'] = 'success';
echo json_encode($response);
?>