Skip to content

Commit

Permalink
P14 --Added products page, structured table, populate dynamic data an…
Browse files Browse the repository at this point in the history
…d updated sql dump
  • Loading branch information
jedavelino committed May 31, 2016
1 parent cd6bd72 commit 51e24a3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 20 deletions.
3 changes: 2 additions & 1 deletion admin/includes/navigation.php
@@ -1,6 +1,6 @@
<!-- Navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#top-navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
Expand All @@ -16,6 +16,7 @@

<li><a href="brands.php">Brands</a></li>
<li><a href="categories.php">Categories</a></li>
<li><a href="products.php">Products</a></li>
<!-- <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo $parent['category']; ?> <span class="caret"></span></a>
<ul class="dropdown-menu">
Expand Down
58 changes: 58 additions & 0 deletions admin/products.php
@@ -0,0 +1,58 @@
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/ecommerce/core/init.php';
include 'includes/head.php';
include 'includes/navigation.php';

$presults = $db->query("SELECT * FROM products WHERE deleted = 0");
if(isset($_GET['featured'])) {
$id = (int)$_GET['id'];
$featured = (int)$_GET['featured'];
//$featuredsql = "UPDATE products SET featured = '{$featured}' WHERE id = '{$id}'";
$db->query("UPDATE products SET featured = '{$featured}' WHERE id = '{$id}'");
header("Location: products.php");
}
?>
<h2 class="text-center">Products</h2>
<a class="btn btn-success pull-right" id="add-product-btn" href="products.php?add=1">Add Product</a>
<div class="clearfix"></div>
<hr>

<table class="table table-bordered table-condensed table-striped">
<thead>
<th></th>
<th>Product</th>
<th>Price</th>
<th>Category</th>
<th>Featured</th>
<th>Sold</th>
</thead>
<tbody>
<?php while($product = mysqli_fetch_assoc($presults)) :
$childID = $product['categories'];
$result = $db->query("SELECT * FROM categories WHERE id = '{$childID}'");
$child = mysqli_fetch_assoc($result);
$parentID = $child['parent'];
$presult = $db->query("SELECT * FROM categories WHERE id = '$parentID'");
$parent = mysqli_fetch_assoc($presult);
$category = $parent['category'].' ~ '.$child['category'];
?>
<tr>
<td>
<a class="btn btn-xs btn-default" href="products.php?edit=<?php echo $product['id']; ?>"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn btn-xs btn-default" href="products.php?delete=<?php echo $product['id']; ?>"><span class="glyphicon glyphicon-remove"></span></a>
</td>
<td><?php echo $product['title']; ?></td>
<td><?php echo money($product['price']); ?></td>
<td><?php echo $category; ?></td>
<td>
<a class="btn btn-xs btn-default" href="products.php?featured=<?php echo (($product['featured'] == 0)?'1' : '0'); ?>&id=<?php echo $product['id']; ?>"><span class="glyphicon glyphicon-<?php echo (($product['featured'] == 1)?'minus': 'plus'); ?>"></span></a>&nbsp; <?php echo (($product['featured'] == 1)?'Featured Product' : ''); ?>
</td>
<td>0</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>


<?php
include 'includes/footer.php';
4 changes: 4 additions & 0 deletions css/main.css
Expand Up @@ -68,4 +68,8 @@ body {
.table-auto {
width: auto;
margin: 0 auto;
}

#add-product-btn {
margin-top: -35px;
}
39 changes: 20 additions & 19 deletions ecommerce_db.sql
@@ -1,11 +1,11 @@
-- phpMyAdmin SQL Dump
-- version 4.5.1
-- version 4.4.3
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: May 31, 2016 at 07:46 AM
-- Server version: 10.1.10-MariaDB
-- PHP Version: 5.6.15
-- Host: localhost
-- Generation Time: May 31, 2016 at 12:00 PM
-- Server version: 5.6.24
-- PHP Version: 5.6.8

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
Expand All @@ -14,7 +14,7 @@ SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `ecommerce_db`
Expand All @@ -26,10 +26,10 @@ SET time_zone = "+00:00";
-- Table structure for table `brand`
--

CREATE TABLE `brand` (
CREATE TABLE IF NOT EXISTS `brand` (
`id` int(11) NOT NULL,
`brand` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `brand`
Expand All @@ -47,11 +47,11 @@ INSERT INTO `brand` (`id`, `brand`) VALUES
-- Table structure for table `categories`
--

CREATE TABLE `categories` (
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(11) NOT NULL,
`category` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`parent` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `categories`
Expand Down Expand Up @@ -86,7 +86,7 @@ INSERT INTO `categories` (`id`, `category`, `parent`) VALUES
-- Table structure for table `products`
--

CREATE TABLE `products` (
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`price` decimal(10,2) NOT NULL,
Expand All @@ -96,16 +96,17 @@ CREATE TABLE `products` (
`image` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`description` text COLLATE utf8_unicode_ci NOT NULL,
`featured` tinyint(4) NOT NULL DEFAULT '0',
`sizes` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
`sizes` text COLLATE utf8_unicode_ci NOT NULL,
`deleted` tinyint(4) NOT NULL DEFAULT '0'
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`id`, `title`, `price`, `list_price`, `brand`, `categories`, `image`, `description`, `featured`, `sizes`) VALUES
(1, 'Levis Jeans', '29.99', '39.99', 1, '6', '/ecommerce/images/products/men4.png', 'These jeans are amazing. They are super comfy and sexy! Buy them.', 1, '28:3,32:5,36:1'),
(2, 'Beautiful Shirt', '19.99', '24.99', 1, '5', '/ecommerce/images/products/men1.png', 'What a beautiful blue colored polo-shirt.', 1, 'Small:3,Medium:6,Large:9');
INSERT INTO `products` (`id`, `title`, `price`, `list_price`, `brand`, `categories`, `image`, `description`, `featured`, `sizes`, `deleted`) VALUES
(1, 'Levis Jeans', '29.99', '39.99', 1, '6', '/ecommerce/images/products/men4.png', 'These jeans are amazing. They are super comfy and sexy! Buy them.', 0, '28:3,32:5,36:1', 0),
(2, 'Beautiful Shirt', '19.99', '24.99', 1, '5', '/ecommerce/images/products/men1.png', 'What a beautiful blue colored polo-shirt.', 0, 'Small:3,Medium:6,Large:9', 0);

--
-- Indexes for dumped tables
Expand Down Expand Up @@ -137,17 +138,17 @@ ALTER TABLE `products`
-- AUTO_INCREMENT for table `brand`
--
ALTER TABLE `brand`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT for table `categories`
--
ALTER TABLE `categories`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=29;
--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=3;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
4 changes: 4 additions & 0 deletions helpers/helpers.php
Expand Up @@ -12,4 +12,8 @@ function display_errors($errors) {

function sanitize($dirty) {
return htmlentities($dirty, ENT_QUOTES, "UTF-8");
}

function money($number) {
return '$'.number_format($number, 2);
}

0 comments on commit 51e24a3

Please sign in to comment.