-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detail.php has been updated. May need to make colors into array for A…
…JAX call. Let me know if changes are needed to make the JSON parse work for you Jack
- Loading branch information
Showing
2 changed files
with
25 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
BradAyers
via email
Author
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm a fan of this code 👍