Posts

Showing posts with the label PHPTutorials

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

PHP Functions Part2

Image
 PHP Functions Tutorial       PART1 Types of User Defined Functions In previous tutorial, you learn what is a function. A function is nothing but a named block, that will perform a specific task.  A function can be written in four ways based on the requirement. 1. Function with no arguments no return 2. function with arguments 3. function with return 4. function with arguments with return. Arguments : are inputs to the function return : function returns the result (output). Note:   arguments and return are optional    1. Function with no arguments no return. TOC Example: <?php function hello () { print ( "Hello world! <br>" ); } hello(); ?> A function, can be called any number of times. <?php function hello () { print ( "Hello world! <br>" ); } hello(); ?>   A function can be called in a loop.     <?php   function hello () { print ( "Hello world! <br>" ); }...

PHP Functions

Image
  Learn Functions in PHP (Part-1)   PART2 PHP provides a plenty of functions. We can create our own functions too, they are called user-defined function. So In PHP, functions can be classified into two types, one is built-in, and the other one is user-defined . In this tutorial, you are going to learn how to create and use your own functions in PHP. You will also learn what are the uses of functions and how many ways you can define your function and how to call those functions. What is a Function in PHP A function is a block of code with some name.  Function will perform some operation ex: addition, subtraction, multiply…etc.,     Advantages of functions: 1. managing programs becomes easy. 2. functions can be reused. So that it saves memory and time. 3. Error handling becomes easy. 4. functions can be used in multiple programs once they defined in one program    Creating Function   Structure of the function function functionName (arguments) { ...

PHP MySQL Using OOPs

Image
    Working with PHP MySQL Using OOPS   In this blog, you are going to learn how to connect with MySQL  database and perform different CRUD operations using Oops based class in PHP. This tutorial explains to you how to create a  class with some functions that are used to maintain the database.  The below given example class having some methods and uses those methods in test class to perform various operations such as listing all the users, testing admin login, deleting a record and so on.     TopMenu  1. Create a table - users with following fields: id username password email 2.  Create dbclass.php and paste the given code below and save in some folder in server. This class having the following functions: dbconn() dbclose() dbselect() dblogin($user,$pwd) dbdelete($user) dbupdate($username,$oldpassword,$newpassword) 3. Create another file dbclasstest.php as given below and run that file in a localhost. Note: Change the db details accordin...

PHP Tutorials Home

Image
 PHP Tutorial for Beginners   Table of Contents   Basic PHP       PHP Introduction     PHP Operators       PHP Conditions      PHP Loops     PHP Arrays     PHP Associative Arrays     PHP String Functions     PHP Array Functions     PHP Functions     PHP Super Global Variables     PHP Forms      PHP File Upload     PHP Sessions     PHP Cookies     PHP MyAdmin Tool     PHP with MySQL        PHP Files       PHP Dates       Advanced PHP         PHP OOPs-1        PHP OOPs-2         Interview Questions in PHP         Practice Questions in PHP Basics   Practice Questions in PHP Arr...

PHP Basics tutorial Operators

Image
    Learn PHP Operators  PHP provides different types of operators. In this tutorial, we discuss some of the operators that we use in coding very frequently.     Table of Contents Arithmetic Operators Assignment Operators. Comparison Operators   Logical Operators. Incrementing/Decrementing Operators. String Operators     Using different types of Operator in PHP 1. Arithmetic Operators [ + - * / % ] in PHP addition(+) subtraction(-)  multiply(*) division(/) modular(%)   <?php   print ( 10 + 20 + 30 );   ?>     Ex2:   <?php   $num1 = 10 ; $ num2= 20 ; $total = $ num1 + $ num2; print 'Total = ' . $total ;   ?> Operator precedence Order of evaluation of an expression 1 ) / * % 2 ) + - 3 ) =      ex: a * ( b+c/d ) * 22 the correct way is: ( a*b ) + ( c/d ) * 22 According to the expression first it goes to division and finally goes to multiplication addition, at l...