Posts

How to read txt file into Html Table

Image
Read content or data from text file and write it into HTML Table     This tutorial explains How to read the contents of a text file and write it into an HTML table using PHP Scripting. Below, there are two files :  1. states.txt: All the data is separated with semicolon(;). Create states.txt and copy below content and save it in a project folder. 2. demo.php: Reads the sates.txt file, displays the data in a table. Create it and save in the same project folder. Start server and open it in a browser. You can see the output as shown in the image down below.   The content of the text file is as follows: states.txt 1;Alabama;Montgomery;5,024,279 2;Alaska;Juneau;733,391 3;Arizona;Phoenix;7,151,502 4;Arkansas;Little Rock;3,011,524 5;California;Sacramento;LosAngeles;3,914,4818   MOVETOP↑    Code explanation: 1. for each loop, reads each row from the file 2. explode function takes two parameters 3. The first one is the character you want to separate(delimiter)...

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...