Read the mechanics first: PHP reads input, calculates a preview, fetches inventory JSON, then renders HTML. This printed example does not execute or reserve stock. Validation and API failure handling are omitted; price rules are for this lab only.
Line 02โ03 (Yellow): Creates two containers in RAM: $apiUrl and an empty $message.
Line 05 (Green): Checks if the customer submitted the form via HTTP POST.
Lines 06โ07 (Green → Yellow): Pulls raw customer input out of $_POST['sku'] and $_POST['sqft'] and stores them in $sku and $sqft.
Line 08 (Orange): Divides Square Feet by 9 and uses ceil() to round UP to the next full Square Yard.
STATION 2 (Lines 13โ18): FETCH LIVE INVENTORY FROM SQL SERVER / C# APIKitchen Analogy: Checking the Walk-In Cooler Clipboard
13// Ask the C# .NET 10 API for the SQL Server inventory
14$rawJson = file_get_contents("$apiUrl/api/inventory");
1516// Decode the JSON text string into a PHP Array of rows
17$products = json_decode($rawJson, true) ?? [];
18?>
Line 14 (Orange → Yellow): Calls the backend API and stores the raw JSON text string inside $rawJson.
Line 17 (Orange → Yellow):json_decode(..., true) unpacks the JSON text into a PHP list of rows named $products.
Line 18 (?>): Closes the top PHP prep block so we can write standard HTML below.
STATION 3 (Lines 19โ38): LOOP OVER ROWS & DISPLAY THE APIโS PUBLIC PRICEKitchen Analogy: Plating Each Dish for the Dining Room
Line 24 & 37 (Blue):foreach ($products as $p) loops through the database array one row at a time, naming the current row $p.
Lines 26โ27 (Blue):<?= stamps the value into HTML, and htmlspecialchars() escapes special characters for this HTML text context.
Lines 29โ33 (Orange): The API decides which price can be public. PHP shows its publicPrice or a withheld-price label. This sends no quote.
๐ฏ Wife's 6-Question Highlighter Quiz (Have Her Ask You These 6 Questions in Any Order!)Point to the Color & Line #
Q1 (Green): "How does PHP know the customer clicked Submit instead of just loading the page?"
→ Line 05: It checks $_SERVER['REQUEST_METHOD'] === 'POST', and reads form fields from $_POST[...] on Lines 06โ07.
Q2 (Orange): "A customer measures their room at 250 SqFt. How does Line 08 calculate carpet yardage?"
→ Line 08:ceil($sqft / 9.0) divides by 9 (3 ft ร 3 ft = 9 SqFt) and rounds UP to 28 SqYd so they aren't short.
Q3 (Yellow): "How does this PHP page get the inventory list from the backend database?"
→ Lines 14 & 17:file_get_contents() fetches the JSON string into $rawJson, and json_decode() turns it into the $products array.
Q4 (Blue): "If the database returns 500 rolls of carpet, how does PHP build 500 table rows in only 14 lines?"
→ Lines 24 & 37: The foreach ($products as $p) loop repeats the single <tr>...</tr> stencil once for every row.
Q5 (Orange): "How does PHP follow the APIโs demo price decision?"
→ Lines 29โ33: Before printing a public price, if ($p['requiresQuote']) shows a withheld-price label. This does not establish manufacturer permission.
Q6 (Blue): "Why wrap raw product or user fields in htmlspecialchars() on Lines 20, 26, and 27?"
→ Lines 26โ27: Escapes this HTML text context. If a raw input field contained <script>, it renders as harmless text.