function show_new_products() { require $_SERVER['DOCUMENT_ROOT'] . '/e_commerce/sql/sql_connexion.php'; require $_SERVER['DOCUMENT_ROOT'] . '/e_commerce/products/common_functions.php'; $request = $bdd->query("SELECT * FROM products ORDER BY id DESC LIMIT 3"); echo '<div id="core_core"> <div id="show_new_products_title">NOUVEAUTÉS</div> <hr width="85%" style="opacity: 0.3; float: right; margin-top: 2.3%; margin-right: 10px;"> <div id="show_new_products_wrapper">'; while ($fetch = $request->fetch()) { echo '<div id="' . $fetch['id'] . '" class="show_new_products_product"> <div class="show_new_products_product_image"> <img src="' . $fetch['image_link'] . '" width="200" height="200"> </div> <div class="show_new_products_product_name">' . $fetch['name'] . '</div> <div class="show_new_products_product_mini_description">' . substr($fetch['mini_description'], 0, 150) . '</div> <div class="show_new_products_product_price">' . putEuroSymbolandSupTagDecimals($fetch['price']) . '</div> </div>'; } echo ' </div> </div>'; }
function show_products_list($menu) { require $_SERVER['DOCUMENT_ROOT'] . '/e_commerce/products/common_functions.php'; require $_SERVER['DOCUMENT_ROOT'] . '/e_commerce/sql/sql_connexion.php'; $request = $bdd->prepare("SELECT * FROM products WHERE category=?"); $request->execute(array($menu)); // $i will be used with modulo to put an alternate grey/white background to the product divs. $i = 0; $backgroundColor = ''; while ($fetch = $request->fetch()) { /* If $i is pair, the background color of the product will be grey. Otherwise, it will be white. */ $i % 2 == 0 ? $backgroundColor = 'grey' : ($backgroundColor = 'white'); if (strlen($fetch['mini_description']) > 150) { // If the description is longer than 78 characters. // We only keep its first 78 characters. $fetch['mini_description'] = substr($fetch['mini_description'], 0, 150) . ' ...'; } echo '<div id="core_core"> <div class="product ' . $backgroundColor . 'Product" id="' . $fetch['id'] . '"> <div class="productLeftFloater"> <div class="product_image"> <img src="' . $fetch['image_link'] . '" /> </div> <div class="product_left_floater_right_floater"> <div class="productName">' . $fetch['name'] . '</div> <div class="productDescription">' . $fetch['mini_description'] . '</div> </div> </div> <div class="productRightFloater"> <div class="productPrice">' . putEuroSymbolandSupTagDecimals($fetch['price']) . '</div> <div class="addToBasket"> <img src="http://image.noelshack.com/fichiers/2015/43/1445621396-addtobasket.png" /> </div> <div class="productQuantitySpinner"> <input class="productQuantitySpinnerInput" value="1"> </div> </div> </div> </div>'; $i++; } $request->closeCursor(); }