Skip to content

Commit

Permalink
detail.php has been updated. May need to make colors into array for A…
Browse files Browse the repository at this point in the history
…JAX call. Let me know if changes are needed to make the JSON parse work for you Jack
  • Loading branch information
BradAyers committed May 17, 2015
1 parent 011fed3 commit 02c1fb9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
44 changes: 20 additions & 24 deletions includes/detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@
<title></title>
</head>
<body>


<?php
include('db.php');
$conn = db_connect();
// $sku = $_POST['sku']; (UNCOMMENT ONCE WORKING TO ALLOW FOR POST REQUESTS)
$sku = "01-12345-01"; // THIS VAR ASSIGNMENT IS TEMPORARY. ONCE WE PASS POST REQUESTS, REMOVE AND UNCOMMENT ABOVE
// $sku = $_POST['sku'];
$sku = "01-12345-01"; // ONLY USE THIS FOR TESTING. ONCE ALL IS WORKING, REMOVE THIS LINE PLEASE

// QUERY DB FOR THE SKU RECEIVED FROM THE POST REQUEST
$sql = "SELECT sku, product, description, quantity FROM Inventory WHERE sku='$sku'";
$sql = "SELECT sku, product, description, quantity, price,color FROM Inventory WHERE sku='$sku'";
$result = $conn->query($sql);


// THE CODE BELOW RENDERS THE SQL RESULTS AS HTML ON THE PAGE IN CASE YOU WANT TO USE ANY OF THIS IN YOUR EJS CONSTRUCTOR
if ($result->num_rows > 0) {
// OUTPUT DATA FOR EACH ROW
while($row = $result->fetch_assoc()) {
// ECHO BELOW CAN BE DELETED WHEN AJAX FETCH IS SET UP
echo "<br /><img src=\"../images/".$row["sku"].".jpg\">
<br /> SKU: ". $row["sku"]. "<br /> Product: ". $row["product"]. "<br />Description: ". $row["description"]."<br />Quantity: ". $row["quantity"]."<br />";
// SQL QUERY BELOW DETERMINES HAT COLORS FOR THE PARTICULAR PRODUCT
// ADD PRICE TO QUERY ABOVE
$hat = $row["product"];
$colors = "SELECT color FROM Inventory WHERE product = ('$hat') AND (size = 'small')";
$hatColors = $conn->query($colors);
while($row = $hatColors->fetch_assoc()) {
echo "<br />Color: ".$row["color"];
}
}
} else {
echo "0 results";
}
$conn->close();
?>
// MAKE RETURN TO SEND ARRAY OF $RESULT TO JSON FOR JACK
$row = $result->fetch_assoc();
$items = $row["sku"].",". $row["product"].",".$row["description"].",".$row["quantity"].",".$row["price"].",".$row["color"];

// SQL QUERY BELOW DETERMINES HAT COLORS FOR THE PARTICULAR PRODUCT
$hat = $row["product"];
$colors = "SELECT color FROM Inventory WHERE product = ('$hat') AND (size = 'small')";
$hatColors = $conn->query($colors);
while($row = $hatColors->fetch_assoc()) {
echo "<br />Color: ".$row["color"];
}

print json_encode($items);
$conn->close();
?>

This comment has been minimized.

Copy link
@nw

nw May 20, 2015

I'm a fan of this code 👍

This comment has been minimized.

Copy link
@BradAyers

BradAyers via email May 20, 2015

Author
</body>
</html>
8 changes: 5 additions & 3 deletions includes/thumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

// MAKE RETURN TO SEND ARRAY OF $RESULT TO JSON FOR JACK
$items = [];
while($row = $result->fetch_assoc())
while ($row = $result->fetch_assoc())
{
$items[] = $row["sku"]. $row["product"].$row["description"];
$items[] = $row["sku"].",".$row["product"].",".$row["description"];
}

print json_encode($items);
print_r($items);

//print json_encode($items);
$conn->close();
?>

0 comments on commit 02c1fb9

Please sign in to comment.