Skip to content

Commit

Permalink
Added tasks 3 and 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Burgin committed Apr 19, 2018
1 parent 781c29b commit 60c412f
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 146 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
146 changes: 0 additions & 146 deletions Task1.php

This file was deleted.

74 changes: 74 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!doctype html>

<html>

<head>
<title>Homework #8</title>
<link rel="stylesheet" href="/~jsburgin/style.css" />
</head>

<body>
<div class="section">
<h3>Task 3</h3>
<p>View all tables and tuples in the database</p>
<a href="/~jsburgin/task3.php" class="button">View Tables</a>
</div>
<div class="section">
<h3>Task 4a</h3>
<h4>Query 1: Songs</h4>
<p>This query shows a list of songs from a particular genre. Select a genre below.</p>
<form action="/~jsburgin/task4a-songs.php" method="POST">
<select name="genre">
<option value="Rock">Rock</option>
<option value="Pop">Pop</option>
<option value="Funk">Funk</option>
<option value="Disco">Disco</option>
<option value="Jazz">Jazz</option>
<option value="Country">Country</option>
<option value="Rap">Rap</option>
</select>
<br />
<button type="submit" class="button">Run Query</button>
</form>

<h4>Query 2: Records & Artists</h4>
<p>This query shows a list of records joined with their artists. Enter a year below to show all records that have come out since then.</p>
<form action="/~jsburgin/task4a-records.php" method="POST">
<input type="text" name="year" placeholder="Enter a year"/>
<br />
<button type="submit" class="button">Run Query</button>
</form>
</div>
<div class="section">
<h3>Task 4b</h3>
<h4>Adding Employees</h4>
<p>This form adds a new employee to the database. Enter employee details below:</p>
<form action="/~jsburgin/task4b.php" method="POST">
<div class="form-group">
<label>SSN:</label>
<input type="text" placeholder="123-45-6789" name="ssn" />
</div>
<div class="form-group">
<label>Name:</label>
<input type="text" placeholder="John Doe" name="name" />
</div>
<div class="form-group">
<label>Address:</label>
<input type="text" placeholder="42 Wallaby Way" name="address" />
</div>
<div class="form-group">
<label>Title:</label>
<input type="text" placeholder="Manager" name="title" />
</div>
<button type="submit" href="/~jsburgin/task1.php" class="button">Add Employee</button>
</form>
<h4>Query Employees</h4>
<p>This query searches for employees by name. Enter a search term below to query.</p>
<form action="/~jsburgin/task4b-search.php" method="POST">
<input type="text" name="name" placeholder="e.g. John"/>
<br />
<button type="submit" class="button">Run Query</button>
</form>
</div>
</body>
</html>
84 changes: 84 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
body {
font-family: 'Helvetica', sans-serif;
margin: 0;
padding: 0;
text-align: center;
}

table {
border-collapse: collapse;
margin: 0 auto;
}

th, td {
border: 1px solid #000;
padding: 5px 10px;
font-weight: normal;
}

h3 {
margin: 0 0 10px;
}

.section {
text-align: center;
padding: 25px 0;
border-bottom: 1px solid #eee;
overflow: auto;
}

select, input {
width: 150px;
margin-bottom: 10px;
height: 28px;
font-size: 15px;
}

input {
text-indent: 8px;
}

button {
margin-bottom: 15px;
}

form {
width: 260px;
margin: 0 auto;
}

.form-group {
width: 100%;
text-align: left;
float: left;
clear: both;
}

.form-group label {
float: left;
clear: both;
margin-bottom: 5px;
}

.form-group input {
float: left;
clear: both;
width: 100%;
}

.button {
background: #6AC2D7;
padding: 10px 15px;
color: #fff;
display: inline-block;
text-decoration: none;
border-radius: 5px;
font-size: 16px;
border: none;
clear: both;
}

a.return-link {
display: inline-block;
margin-top: 20px;
}
55 changes: 55 additions & 0 deletions task3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
$user = "jsburgin";
$cwid = "11484207";
$server = "cs-sql2014.ua-net.ua.edu";
// create the connection to mySQL
$con = new mysqli($server, $user, $cwid, $user);
$tables = $con->query("SHOW TABLES");

function getRows($con, $tname) {
return $con->query("SELECT * FROM " . $tname);
}

function getColumns($con, $tname) {
return $con->query("SHOW COLUMNS FROM ". $tname);
}
?>

<!doctype html>
<html>
<head>
<title>Task 3</title>
<link href="/~jsburgin/style.css" rel="stylesheet" />
</head>

<body>
<a href="/~jsburgin" class="return-link">Return to Main Page</a>
<?php
while ($table = mysqli_fetch_row($tables)) {
$columns = getColumns($con, $table[0]);
$rows = getRows($con, $table[0]); ?>

<div class="section">
<h3><?php echo $table[0] ?></h3>
<table>
<thead>
<tr>
<?php while ($column = mysqli_fetch_row($columns)) { ?>
<th><?php echo $column[0]; ?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_row($rows)) { ?>
<tr>
<?php foreach($row as $value) {?>
<td><?php echo $value ?></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
</body>
</html>
Loading

0 comments on commit 60c412f

Please sign in to comment.