Categories
makitweb.com

Export Data in Excel and CSV format with Laravel Excel

Laravel Excel is a package which simplifies the import and export data in Laravel.

It allows exporting data in various format – xlsx, csv, xml, html, pdf, etc.

Require to create a separate class from where return data and set heading row.

In this tutorial, I am using it to export MySQL data in CSV and Excel format in Laravel project.

Export data in Excel and CSV format with Laravel Excel

Categories
alexwebdevelop.com

A step-by-step, 5 days program to learn PHP from scratch (for absolute beginners)

[et_pb_section fb_built=”1″ module_class=”underline_links” _builder_version=”3.22″][et_pb_row _builder_version=”3.25″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” custom_padding=”27px|0px|27px|0px”][et_pb_column type=”4_4″ _builder_version=”3.25″ custom_padding=”|||” custom_padding__hover=”|||”][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”2em” ol_font=”||||||||” background_size=”initial” background_position=”top_left” background_repeat=”repeat”]

You decided to learn PHP and become a web developer? Great!

But let me guess:

  • you want to learn the basics in less than a week,
  • even if you have no coding experience.

 

Is it possible? Yes, definitely, but you need a learning plan.

This guide is what you need:

it will show you how to start from scratch and how to learn the basics in just 5 days without wasting a minute of your time.

Ready?

Let’s get started!

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”15px” link_font=”||||||||” link_font_size=”14px” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” ol_font=”||||||||” ol_font_size=”15px” ol_line_height=”1.8em” header_font=”||||||||” header_3_font=”||||||||” header_3_font_size=”20px”]

Table of contents

  1. PHP introduction: what to read
  2. PHP in practice: getting started
  3. The 5-days learning program
  4. The mistakes you must avoid
  5. Conclusion

 

[/et_pb_text][et_pb_text disabled_on=”on|off|off” _builder_version=”3.27.4″]

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/how-to-learn-php.png” alt=”How to learn PHP” title_text=”How to learn PHP” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″ custom_margin=”||5px|” custom_padding=”|||”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#666666″ text_font_size=”12px” link_font=”||||||||” link_font_size=”11px” text_orientation=”center” custom_margin=”|||” custom_padding=”|||”]Designed by Freepik
[/et_pb_text][/et_pb_column][/et_pb_row][et_pb_row _builder_version=”3.25″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” custom_padding=”27px|0px|27px|0px”][et_pb_column type=”4_4″ _builder_version=”3.25″ custom_padding=”|||” custom_padding__hover=”|||”][et_pb_text disabled_on=”on|off|off” _builder_version=”3.27.4″]

 

[/et_pb_text][et_pb_text module_id=”php-introduction” _builder_version=”3.27.4″]

 

PHP INTRODUCTION: WHAT TO READ

[/et_pb_text][et_pb_blurb use_icon=”on” font_icon=”%%72%%” icon_color=”#0c71c3″ _builder_version=”3.15″ animation=”off”][/et_pb_blurb][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

Even if you never wrote a single line of PHP, you don’t need to spend a lot of time reading long and boring manuals or How-Tos.

And as long as you are learning the basics, you don’t need to read books either.

 

That said, it would be a mistake to start coding without any idea of what PHP is and what its main features are.

Yes, PHP is best learnt with practice, but even so it’s important to know the language’s fundamentals.

 

“What should I do, then?”

It’s easy: the PHP official website offers a nice and easy introduction that is more than enough to grasp the language fundamentals, even if you never used PHP before.

But wait: you don’t need to read the whole introduction. In fact, I selected for you the specific pages you should read.

You can probably read everything in less than 1 hour. Prepare yourself a good cup of coffee and you’ll be good to go.

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/09/reading-with-coffee.jpg” alt=”Reading with coffee” title_text=”Reading with coffee” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

The first five pages are taken from the Introduction chapter.

They contain both theory and practical tutorials that will let you understand how PHP works. Be sure to read them in order:

  • What is PHP?
    The VERY basics (5 minutes read)
  • What can PHP do?
    A bit more theoretical introduction (5 minutes read)
  • Your first PHP-enabled page
    A “Hello World” tutorial plus some basic suggestions (10 minutes read)
  • Something Useful
    Some more practical examples to get a grasp of the language capabilities (10 minutes read)
  • Dealing with Forms
    A quick HTML form integration tutorial, useful to understand how HTML and PHP relate to each other (5 minutes read)

 

The next three pages are taken from the Language Reference section.

You will go back to this section quite often. For now, focus on just these three pages:

  • Introduction
    A short practical introduction to variables and types (5 minutes read)
  • Basics
    Some basic syntax (10 minutes read)
  • User-defined functions
    An introduction to user-defined functions (10 minutes read)

 

Don’t worry if you can’t remember everything you just read. For now, it’s important that you understand how PHP works and what its main features are.

You’re free to read more introduction chapters if you want, but it’s not strictly necessary.

When you’re done, move on to the next step.

 

 

[/et_pb_text][et_pb_text module_id=”php-in-practice” _builder_version=”3.27.4″]

 

PHP IN PRACTICE: GETTING STARTED

[/et_pb_text][et_pb_blurb use_icon=”on” font_icon=”%%173%%” icon_color=”#0c71c3″ use_icon_font_size=”on” icon_font_size=”72px” _builder_version=”3.15″ animation=”off”][/et_pb_blurb][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

Now it’s time to write some PHP code.

You need two things to get started: a development environment to run your PHP scripts and a code editor to write the code.

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||”]

1. Install a local development environment

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

PHP is a scripting language. To execute a PHP script, you need an interpreter that understands and runs the code.

When you open a PHP webpage online, the remote web server acts as PHP interpreter executing the PHP code and sending the output to your browser.

This is how a dynamic webpage is created 😉

 

A development environment, or DE, is a software package that mimics a server environment on your local computer.

A DE provides you with everything you need to develop PHP applications: a local web server, a SQL database (usually MySQL) and other utilities like PhpMyAdmin.

There are many high quality, free packages you can choose from: XAMPP, WAMP (or MAMP if you have a Mac), EasyPHP and others.

If you’re not sure which one to go with, try XAMPP: it’s up to date, easy to use, cross-platform and open source.

Just to give you an idea, this is how the XAMPP control panel looks like:

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/09/xampp-control-panel.png” alt=”XAMPP control panel” title_text=”XAMPP control panel” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em”]

 

From there you can start and stop the services you need (the web server, the SQL server…), access the directory where the web server looks for PHP scripts, edit the configuration and so on.

It’s very easy to use and you don’t have to worry about all the technical details.

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em”]

2. Install a code editor

[/et_pb_text][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

A code editor is basically an advanced text editor that helps you writing your code.

Modern code editors have many useful functionalities, including:

  • line numbers;
  • code highlighting for multiple languages;
  • code autocompletion and assist (automatically complete keywords, close open brackets and so on);
  • advanced search functionalities;
  • plugins and extensions support;
  • …and more.

This is how Atom, one of the most used code editors, looks like:

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/atom.jpg” alt=”Atom screenshot” title_text=”Atom screenshot” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

Some of the most used code editors are Notepad++, Atom, Brackets and Sublime Text. All these but Sublime Text are free.

Pick the one you like the most, but don’t waste your time looking for the best. For now, your time it’s much better spent coding.

[/et_pb_text][et_pb_code background_size=”initial” background_position=”top_left” background_repeat=”repeat”]  [easy-tweet tweet=”Get started with PHP in just 5 days with this step-by-step guide” via=”no” hashtags=”PHP”][/et_pb_code][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

3. Start coding

[/et_pb_text][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#222222″ text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

Now it’s finally time to write your first PHP Hello World script.

Start your development environment and make sure the web server is running. Then, open a web browser and type localhost in the URL bar.

You will see the DE’s homepage. If you are using XAMPP, the page will look like this:

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/09/xampp-homepage.png” alt=”XAMPP homepage” title_text=”XAMPP homepage” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

Your PHP scripts must be placed inside a directory called webserver root.

This is usually the htdocs directory located inside the development environment own installation directory.

In XAMPP, you can open this directory from the XAMPP Control Panel by clicking on the Explorer button and then opening the htdocs directory:

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/09/xampp-explorer.png” alt=”XAMPP explorer” title_text=”XAMPP explorer” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||on||||||” text_font_size=”14px” ul_font=”||||||||” text_orientation=”center”]First, click on the “Explorer” button…
[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/09/htdocs.png” alt=”htdocs” title_text=”htdocs” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″ custom_margin=”40px|||”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||on||||||” text_font_size=”14px” ul_font=”||||||||” text_orientation=”center”]

…then open the “htdocs” directory.

[/et_pb_text][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

Remember: this is where you must  save your scripts.

Now open your code editor and paste the following PHP code: 

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”13px”]

<?php

echo '<h1 style="text-align: center;">Hello World!</h1>';

[/et_pb_text][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

Save the file inside the htdocs directory as hello_world.php (you can use any file name you want, just be sure to use the .php extension), then go back to your web browser and open the URL:

http://localhost/hello_world.php

 

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/09/php-hello-world.png” alt=”PHP hello world” title_text=”PHP hello world” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

Congratulations, you just completed your first PHP webpage!

[/et_pb_text][et_pb_image src=”https://media.giphy.com/media/14cDsqOkks6O8U/giphy.gif” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″ max_width=”80%” max_width_tablet=”100%” max_width_phone=”100%” max_width_last_edited=”on|desktop” module_alignment=”center”][/et_pb_image][et_pb_text ul_position=”inside” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”16px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

 

Feel free to experiment with the code. You can also try to replicate the examples from the Introduction chapters.

If you have any doubt or if you need help running your development environment, leave a comment or join my Facebook group Alex PHP café. 

Ready? Let’s move on.

 

[/et_pb_text][et_pb_text module_id=”learning-php” _builder_version=”3.27.4″ custom_margin=”||0px|” custom_padding=”|||”]

 

 

THE 5-DAYS LEARNING PROGRAM

[/et_pb_text][et_pb_blurb use_icon=”on” font_icon=”%%130%%” icon_color=”#0c71c3″ use_icon_font_size=”on” icon_font_size=”72px” _builder_version=”3.15″ animation=”off”][/et_pb_blurb][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

Let it be clear: you cannot learn everything about PHP in 5 days.

Learning a programming language is a never-ending process: the more you practice the more you learn.

But before you can improve your coding skills on your own, you must first learn the basics.

Many beginners spend way too much time in this first learning phase because they all make the same mistake: they don’t follow any learning program.

I know, because I made the same mistake too.

 

This guide provides you with a 5 days learning program you can stick with to acquire your basic skills without wasting your time. This program is:

  • focused on what really matters: there is no point in learning too much at once;
  • balanced: you can stick with it even if you don’t have much time;
  • and effective: after the 5 days you can start writing real PHP applications right away.

Let’s begin.

 

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

DAY 1: PHP AND HTML

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/01/coding-isometric-01.png” alt=”PHP and HTML” title_text=”PHP and HTML” _builder_version=”3.23″ max_width=”20%” max_width_tablet=”20%” max_width_phone=”30%” max_width_last_edited=”on|phone” module_alignment=”left” always_center_on_mobile=”off”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

The very first thing to learn is how PHP and HTML are related to each other.

Start from this basic HTML form tutorial: Dealing with Forms

This tutorial explains how to build a PHP backend to handle data from an HTML form. You should also read how the $_REQUEST, $_POST and $_GET Superglobals work (hint: they contain the data from HTML forms).

You can safely ignore XForms: you won’t use them anytime soon.

If you want to take a step further, see how to use forms to upload files too: Handling file uploads

 

Once you have read and understood the tutorial, it’s time to create your own PHP form backend.

Open your code editor and create an HTML form like the one in the tutorial, changing the fields’ names and formats as you like. Then, write the PHP backend script and test everything with your development environment.

Important: do not skip this step, because you will use this exercise in the next 4 days too.

This first day should be quite easy, but feel free to ask me if you have any doubt. 

 

[/et_pb_text][et_pb_blurb use_icon=”on” font_icon=”%%291%%” icon_color=”#0c71c3″ icon_placement=”left” content_max_width=”720px” use_icon_font_size=”on” icon_font_size=”48px” content_max_width_last_edited=”off|desktop” icon_font_size_last_edited=”off|desktop” _builder_version=”3.15″ body_font=”||||||||” body_text_color=”#0c71c3″]

Would you like to talk with me and other developers about PHP and web development? Join my Facebook Group: Alex PHP café

See you there 🙂

[/et_pb_blurb][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

DAY 2: OPERATORS, FUNCTIONS AND STRINGS

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/01/coding-isometric-01.png” alt=”PHP and HTML” title_text=”PHP and HTML” _builder_version=”3.23″ max_width=”20%” max_width_tablet=”20%” max_width_phone=”30%” max_width_last_edited=”on|phone” module_alignment=”left” always_center_on_mobile=”off”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

If you have some experience with any programming language, I’m sure you already know what operators and functions are.

And if you do not, don’t worry: they are very intuitive concepts and you’ll grasp them very quickly.

First, read the operators documentation to understand what operators are and how they work in PHP.

You don’t need to read all the chapters. Just focus on the most important operators, the ones you will use from the start:

It’s perfectly fine if you don’t remember everything (or even half of what you read). Your goal is to discover what you can do with PHP and understand its potential.

Then, move on to functions. Focus on the basics:

 

In DAY 2 you will also study strings.

Strings are extensively used in web programming and the PHP standard library includes many string-handling functions that you will use very often.

Now get back to your exercise from day 1 (you DID it, right…?)

You are going to add some additional functionalities using operators, custom function definitions and string-handling functions.

You can do whatever you want, just think of a nice functionality to include in your backend and try to implement it. It can also be something completely useless but funny.

 

If you need some inspiration, look at the following example: It reads a value from the request string (like an input value from an HTML form) and prints the even characters only.

This example uses some operators (increment, string concatenation, arithmetic) a couple of string functions and it also shows how to write a user-defined function:

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”13px”]

<?php

/* Read a "request string" */
$string= $_REQUEST['input'];

/* Calls a user-defined function */
echo even_letters($string);

/* Function body */
function even_letters($string)
{
   $result = '';
   
   /* strlen() returns the length of a string */
   for ($i = 0; $i < strlen($string); $i++)
   {
      /* Note: string positions start from 0, so we must consider odd indexes to get even letters */
      if (($i % 2) != 0)
      {
         /* Note the .= operator... remember what it does? */
         $result .= substr($string, $i, 1);
      }
   }
   
   return $result;
}

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

DAY 3: OOP (object-oriented programming)

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/01/coding-isometric-01.png” alt=”PHP and HTML” title_text=”PHP and HTML” _builder_version=”3.23″ max_width=”20%” max_width_tablet=”20%” max_width_phone=”30%” max_width_last_edited=”on|phone” module_alignment=”left” always_center_on_mobile=”off”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”1.7em” custom_margin=”||0px|” custom_padding=”|||”]

Object-oriented programming is an important programming paradigm used my many modern languages.

It can be a bit difficult to grasp at first, but it’s important that you start using it as soon as possible.

Again, if you are already familiar with OOP concepts from any other programming language then you will find PHP’s OOP easy to understand.

 

If you’re unfamiliar with OOP, take some time to read a few chapters from the documentation. It won’t take too much but stay focused and read them without distractions.

These are the specific chapters you should be familiar with:

 

You can see a practical example of how classes work in PHP in my User Authentication guide and in my PHPMailer tutorial.

You will probably find them a bit complex, but don’t worry: you’re not expected to understand everything about OOP in one day. Your goal is to grasp the basic concepts and learn how to use them in practice.

Again, go back to your exercise and start practicing with OOP.

Understand as much as you can from my tutorials’ examples and from the PHP documentation, then create your own class. A very simple one will do, but practice as much as you can.

For example, you can turn the HTML form into a login form with a username field and a password field, then write a very simple authentication class in your PHP backend.

You should try doing it on your own, but feel free to share your results in the comments or on my Facebook group.

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_text_color=”#555555″ text_font_size=”15px” text_line_height=”1em” ul_font=”||||||||” text_orientation=”center”]

 

 

I hope you are enjoying this guide! Why don’t you share it with your friends?
It’s just 1 second of your time and you’ll make me happy!

[/et_pb_text][et_pb_code text_orientation=”center”]

[/et_pb_code][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

DAY 4: SESSIONS

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/01/coding-isometric-01.png” alt=”PHP and HTML” title_text=”PHP and HTML” _builder_version=”3.23″ max_width=”20%” max_width_tablet=”20%” max_width_phone=”30%” max_width_last_edited=”on|phone” module_alignment=”left” always_center_on_mobile=”off”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” header_font=”||||||||” custom_margin=”||0px|” custom_padding=”|||”]

PHP uses Sessions to keep track of consecutive remote user access.

Sessions are used extensively for user authentication to keep track of user logins, in e-commerce websites to keep track of accounts’ purchases and in many other scenarios.

Almost every PHP-based website uses Sessions.

 

It’s a good idea to learn Sessions from the start, because they will let you write stateful websites very easily. 

You can go straight to my Sessions complete guide to learn how to use Sessions in practice and to see some code examples.

 

Of course, don’t forget to use Sessions in your own form example. If you created an authentication class as OOP exercise, you could use Sessions to remember user accesses.

Otherwise, a simpler exercise is to remember all the values sent through the HTML form and print the list at every page load:

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”13px”]

<?php

/* Start the session */
session_start();

/*  Note:
   array_key_exists() is used to check whether an array key is set and to avoid "undefined" notices
*/

if (!array_key_exists('names', $_SESSION))
{
   /* Create the names array if it doesn't exist */
   $_SESSION['names'] = array();
}

if (!array_key_exists('ages', $_SESSION))
{
   /* Create the ages array if it doesn't exist */
   $_SESSION['ages'] = array();
}

$name = '';
$age = '';

if (array_key_exists('name', $_REQUEST))
{
   /* Read the name value from the request string */
   $name = trim($_REQUEST['name']);
}

if (array_key_exists('age', $_REQUEST))
{
   /* Read the age value from the request string */
   $age = trim($_REQUEST['age']);
}

/* Avoid adding empty values to the array */
if (strlen($name) > 0)
{
   $_SESSION['names'][] = $name;
}

if (strlen($age) > 0)
{
   $_SESSION['ages'][] = $age;
}

?>

<form action="backend.php" method="post">
 <p>Your name: <input type="text" name="name" /></p>
 <p>Your age: <input type="text" name="age" /></p>
 <p><input type="submit" /></p>
</form>
<br><br>

Your names so far:
<br>

<?php

foreach ($_SESSION['names'] as $name)
{
   echo $name . '<br>';
}

?>

<br><br>
Your ages so far:
<br>

<?php

foreach ($_SESSION['ages'] as $age)
{
   echo $age . '<br>';
}

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

DAY 5: PHP AND DATABASES

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/01/coding-isometric-01.png” alt=”PHP and HTML” title_text=”PHP and HTML” _builder_version=”3.23″ max_width=”20%” max_width_tablet=”20%” max_width_phone=”30%” max_width_last_edited=”on|phone” module_alignment=”left” always_center_on_mobile=”off”][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

Almost all dynamic websites need to store some data.

An e-commerce site must store orders and customers’ information, a blog must store posts and settings, and so on.

All this data is stored on a database, usually an SQL rational database like MySQL.

Imagine a database as a set of tables. Inside each table, a row represents an element and every column of the row is an element’s attribute.

For example, a “Users†table could contain all the users registered on a website.

Every user is saved on a table’s row, where each column contains a user’s attributes (name, password, registration date etc.). For example, this is the users table I used in my JSON tutorial:

 

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/sql-table-example.jpg” alt=”SQL table example” title_text=”SQL table example” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][/et_pb_column][/et_pb_row][et_pb_row _builder_version=”3.25″ custom_padding=”27px|0px|27px|0px”][et_pb_column type=”4_4″ _builder_version=”3.25″ custom_padding=”|||” custom_padding__hover=”|||”][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

To get started, you can look at my PDO connection example (PDO is the suggested PHP extension for databases). 

Explaining databases is far beyond the scope of this guide, but you can find a lot of excellent tutorials online.

Also, you will be happy to know that your development environment already has an SQL server (likely MySQL) and everything you need to use it including PhpMyAdmin, the de facto standard web app for MySQL administration.

[/et_pb_text][et_pb_text module_id=”php-mistakes” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

THE MISTAKES YOU MUST AVOID

[/et_pb_text][et_pb_blurb use_icon=”on” font_icon=”%%219%%” icon_color=”#e0621f” use_icon_font_size=”on” icon_font_size=”72px” _builder_version=”3.15″ animation=”off”][/et_pb_blurb][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 I want you to get the most out of your 5 days learning session. You already know what to do during each day, but it’s also important to know what to avoid.

In this last chapter I’ll show you the 4 most common mistakes you should look out for and how to successfully avoid them.

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

MISTAKE #1: DON’T STICKING TO PHP

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/php-focus-small.png” alt=”Focus on PHP” title_text=”Focus on PHP” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” link_font=”||||||||” link_font_size=”10px”]

Designed by Freepik

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

The life of a web developer is complicated. With so many languages to learn, it can be difficult to focus on just one.

During these 5 days, you will probably be tempted to look at other languages like JavaScript or Python or to try using some PHP framework.

But that’s not a good idea: 5 days are a very short time frame, and during that time your brain needs to stay focused 100% on the same thing.

Focus on PHP only and you will learn it well.

You will have plenty of time later to think about the rest.

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

MISTAKE #2: DON’T SCHEDULING YOUR DAYS

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/calendar.png” alt=”Calendar” title_text=”Calendar” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” link_font=”||||||||” link_font_size=”10px”]

Designed by Freepik

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

Before you begin your study session, be sure to plan all the 5 days in advance.

If you don’t, how can you be sure you can find the time to study each day?

To get the most out of this learning program, it’s important that you practice every day. Your brain will learn better and faster if you do so.

It’s much better to practice one hour every day than two hours every other day.

This is what I suggest you do:

  • decide in advance how many hours you need to study each day (from 1 hour if you already have some programming experience, up to 3 hours if you are an absolute beginner);
  • use your favourite calendar app to schedule the time slots for each of the 5 days;
  • don’t let anything keep you from studying during these time slots, except real emergencies.

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

MISTAKE #3: DISTRACTIONS

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/notifications.png” alt=”Notifications” title_text=”Notifications” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” link_font=”||||||||” link_font_size=”10px”]

Designed by Freepik

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” ul_font=”||||||||” ul_font_size=”17px” ul_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

Today, distractions are one of the greatest obstacles to productivity.

It’s hard to be able to work for more than 10 minutes without being interrupted by a notification from our smartphone, a new email or a Facebook message.

Countless studies and books (like the excellent Deep Work by Cal Newport) clearly show how these distractions are much more harmful than we think, especially when we need to focus on an intellectual work.

Learning a new programming language in just a few days requires a high level of attention and focus, and distractions can very easily take them away from you.

This is what I suggest you do during your PHP study sessions:

  • turn off your smartphone, or at least turn off the sound and put it away from you. Don’t worry, nothing bad will happen if you don’t look at it for a few hours;
  • don’t open any webpage you don’t need, including social networks, emails and chats;
  • some kind of music or sounds (like white noise or nature sounds as rain or river water flow) can help focus. Give it a try. When I need to focus on writing, I often put my headphones on and listen to Rainy Mood.

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

MISTAKE #4: SKIPPING PRACTICE

[/et_pb_text][et_pb_image src=”https://alexwebdevelop.com/wp-content/uploads/2018/10/poker-face.jpg” alt=”poker face” title_text=”poker face” align=”center” align_tablet=”center” align_last_edited=”on|desktop” _builder_version=”3.23″][/et_pb_image][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

Reading the documentation chapters and the examples is not enough, even if you understand everything you read.

For your brain to really learn a concept, that concept must be stored in memory and then retrieved multiple times. The more you recall something the more you will remember it (this is the fundamental theory behind many learning strategies like spaced repetition).

Sometimes you may be tempted to skip doing the exercises, especially if you understood perfectly the theory. But if you do so, you will probably forget everything in a couple of days.

[/et_pb_text][et_pb_text module_id=”conclusion” _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

 

 

CONCLUSION

 

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ text_font=”||||||||” text_font_size=”17px” text_line_height=”2em” link_font=”||||||||” link_font_size=”17px” link_line_height=”2em” custom_margin=”||0px|” custom_padding=”|||”]

In this step-by-step tutorial you have learned how to get started with PHP, including how to install a development environment and a code editor.

The 5 days learning program explained in this guide will let you acquire the right basic skills, the ones you will use right away in your first PHP applications, without wasting your time.

You also know which mistakes to avoid getting the most out of the learning session.

Now, why don’t you share your learning experience? Did you try this learning program or something else? And how did it go?

I’m waiting for your comments!

[/et_pb_text][et_pb_text _builder_version=”3.27.4″ custom_margin=”|||”]

 

P.s. If this guide has been helpful to you, please spend a second of your time to share it… thanks!

[/et_pb_text][et_pb_text _builder_version=”3.27.4″]

 

Alex

[/et_pb_text][et_pb_code][/et_pb_code][/et_pb_column][/et_pb_row][/et_pb_section]

Categories
makitweb.com

Auto populate Dropdown with jQuery AJAX in Laravel

Autopopulating values require when need to load records on child element based on parent element value.

Element values replace with new items whenever parent element value changes.

In this tutorial, I show how you can auto-populate dropdown with jQuery AJAX in Laravel.

Auto populate Dropdown with jQuery AJAX in Laravel