PHP Echo to Display the File from the Database to the Website



One of PHO syntaxes is echo(). For your information, PHP is one of popular scripting languages to access database. Originally, this script was for website to enhance HTML capabilities. Nowadays, you can see PHP in database application to retrieve or access it. Echo can be interpreted as display. The example of this syntax is PHP echo statement. PHP is also capable to replace HTML script. The benefit of this script is that it's more dynamic due to integration with server and database.

Creating Text Display in PHP

1.      Using echo
Before knowing about echo (), displaying output can be used with two syntaxes. Firstly, PHP incorporates echo without return command. The second value is print. Both of them use similar basic PHP lines.

The simplest of echo is without specifying variables. As you know, PHP is similar to language programming that requires variables and values. This method only works when website is simple and only intends to display text.

The next part is echo with variables. PHP was developed to help server retrieves data quickly from database and sends to client or end-user. Developer does not have to write long codes to get the data. On contrary, simple script from end-user refers to complex PHP lines in server. After that, the data will be sent immediately. To simplified commands, PHP uses variables, including echo tag. To display environment variables, you need to write echo statement that refers to variables.

Variables might be defined in single mode. One variable contains single value, such as color with red and the car with Volvo. This method is effective for small number of variables. Unfortunately, you need to arrange values into same variables to save your time. This method is called array. Meanwhile, echo is able to display variable by only referring to value and index.

2.      Print statement
Another similar syntax is PHP print Statement. You can write print() to identify as print statement. Basic capability of this tag is similar to echo, but print has return value. To put in simple explanation, you may see in website with form. After completing question, user is able to show preview of form before decide to submit it. This preview is created using print statement. The benefit is that preview is not officially definite, so user can go back to edit or change the data.

Print also comes in handy to display information then go back to search section. Echo only shows the final result, but print gives slightly idea what kind of information that will be displayed. As similar to echo, the print statement can take several variables at once then put them together. It also synchronizes perfectly with array. In order to show multiple values, you just refer to key of particular values.

How to use print for multiple variables? Firstly, variables are defined in separate way. Each of variables can be distinguished. For example, you use X for color and Y for the car brand. Both variables are array modes, so there are many values with no defined index, but still countable. The car consists of ten brands and color has six options. Server will display variable based on what user want. Type variable X then follow with Y respectively. Print statement will display certain information, for example red BMW and silver Chevrolet.

SHARE

About andy

I made this blog just to make about the science that I learned during the study, if there is something wrong please comment below, and do not forget to share, thank you.

    Blogger Comment
    Facebook Comment

0 komentar:

Posting Komentar