Posts

Showing posts from June, 2023

Recently viewed list in PHP Mysql

Image
 Recently viewed list in PHP MySQL        Learn How to show recently viewed products list in a PHP website using MySQL Database . In the previous tutorial, you learn how to get the last five product IDs in an array. In this tutorial, we use MySQL to get the details of each product from recently viewed, and display them in the bottom of the product details page. Here we're using two files, one is bookdetails.php and another is recentlyviewed.php. In Bookdetails.php bookid is added to a session array 'lastviewed' every time when user clicks on some book. bookdetails.php <?php @ session_start (); include "connect.php" ; //check if //A) a bookid has been submitted //B) the submitted value is numeric $auth = "" ; if ( isset ( $_GET [ 'bid' ])){ //clean it up if (! is_numeric ( $_GET [ 'bid' ])){ //Non numeric value entered. Someone tampered with the catid $error = true ; $errormsg = " Security, Serious error. Contact webmast

Create Recently Viewed list, PHP Array

Image
How to show a list of recently viewed products in PHP Mostly when you are visiting ecommerce websites, you will see a short browsing history of recently view products. This list allows the user to visit back again more easily to a product page they have just seen or add it to a wishlist or as a reminder. So that they don’t forget about something which may have interested them. In this tutorial, you will learn how to display the last 5 products viewed , by storing the product ID from the product details page in an array within the session. Steps: Here are some steps that we need to follow to achieve… • Add the clicked product's ID to an array when the product detail page is visited by a user. • Store up to 5 product IDs in the array. • Skip the same product being added to the array twice. • Show the collected product IDs in an array. Step 1: Adding the product ID to an array. At the top of the product detail page, create a session, and set the value. Here, we used 'recentlyviewe

ES6- Spread Operator

Image
       Spread Operator(...) in ES6   Using the Spread Operator, you can copy a part of an existing array into another array. The spread operator, one of new feature added in the JavaScript ES6 version.   < script> const arr1 = [ 'a' , 'b' , 'c' ]; const arr2 = [ 'd' , 'e' , 'f' ]; const arrCombined = [...arr1, ...arr2]; document .write(arrCombined); < /script>   The spread operator with destructuring. Example   Assign the first and second items from numbers to variables and put the rest in an array: const arr1 = [ 1 , 2 , 3 , 4 , 5 , 6 ]; const [one, two, ...rest] = arr1;     spread operator with functions      TOP If the spread operator is used as a parameter, it is known as the rest parameter. You can also accept multiple arguments in a function call using the rest parameter .  Example,   let func1 = function (...args) { console.log(args); } func1( 3 ); // [3] func1( 4 , 5 , 6 ); // [4, 5, 6]   Example2,