PHP Tutorial Arrays & Loops | Promotion Forum

PHP, like many other languages, uses matrices to store information. Arrays can help keep data organized, easily retrievable and even translated into / from other languages ​​(such as JavaScript) to allow PHP to play with the user information that someone sent in a form. There are many different things we can do with the arrangements, but today we will simply discuss what they are, how to create one and how to "cycle" through them. I will show you an example that shows why the loop is an important skill that you should know in PHP or in any other language.

If you want to learn some basic PHP, you can check my PHP Tutorial for beginners that explains how to create / start a PHP file, declare variables, analyze variables (with if / else statements), display information on the page and combine strings of information together. Here we'll do a little bit of all that, so make sure you've read that tutorial first.

This tutorial will be repetitive to help you understand the matrices and loops. Enjoy!

tutorial.php

Code:

"Ghost", "age" => 25);
// we have started a matrix with a name and age value
?>

In this example we have two matrices. One of them is empty, and one of them is storing my current age and my username. As you can see, starting a matrix is ​​as easy as having its variable (like $ data) and then using the syntax training();
Within the matrix, you can do a variety of things. First we will take a look at our $ info matrix, which is a associative matrix.

tutorial.php

Code:

"Ghost", "age" => 25); // associative matrix
echo $ info["name"]; // echo the value of the name of our matrix
$ myage = $ info["age"]; // set our age value to a variable
?>

In this example we did two things. First, we echoed my name on the page. If we opened our PHP page, I would literally just say "Ghost" on the page. Age is not echoing, so it would not appear.

The reason why I made the variable $ myage was to show you that you can assign a value of matrix to a variable. This can be very useful for large arrays to prevent your script from having to read through a large array to get information. For example, if a matrix has 100 different data within it, it can be very beneficial to declare a variable for information like the one I made with $ myage if you plan to use the value much later.

Associative matrices essentially "associate" a name key with a value.
A key is what you see in the [] part of the recovery of the matrix. For example in $ info[“name”], the key is "name". In the following example, our key will be a number instead of a string.

tutorial.php

Code:

"Phantom", "age" => 25, "role" => 2); // associative matrix

$ groups = array (0 => "User", 1 => "Moderator", 2 => "Administrator);
// This is a numerical matrix.

// Let's use the string concatenation of the PHP tutorial for beginners to show some sentences:
echo $ groups[0] . "It's the paper 0 
"; echo $ groups[1] . "is the role 1
"; echo $ groups[0] . "It's paper 2
"; ?>

Therefore, a number matrix increases by 1 each time a new value is added to the matrix. We can configure the matrix as I did, or we can add a value to the matrix quite simply. Watch this:

tutorial.php

Code:

"Phantom", "age" => 25, "role" => 2); // associative matrix

$ groups = array ();
// This is an empty matrix.

$ groups[] = "User";
$ groups[] = "Moderator";
$ groups[] = "Administrator";

$ role = $ info["role"];
echo "{$ info["name"]} is a company {$ groups[$role]} ";
?>

In this last example, we are using the information of role = 2 in the $ info matrix to find the name of the function in our matrix $ groups. We are also adding the roles to our $ groups array in a different way than before. When you use $ arrayName[] , is telling PHP that everything that comes after the equal sign must be added to that matrix.

So when we use $ groups[] = "User" first, then the groups look like this:

Code:

$ groups = array (0 => "User");

So obviously we add Moderator and Administrator too.
You may also have noticed that we use { Y } Around our variables / matrix references in our sentence. This is a way to make sure that quotes and syntax do not break our string value within the original "double quotes". It is similar to just using a variable within a string, but it is an additional syntax that does not change the value of our real variable, it only allows PHP to read it without any problem.

In our previous example, our tutorials page now shows:
"Ghost is an administrator of the company."

So, now that you know how to set up an associative array ($ info), a numeric array ($ groups) and an empty array to which we can add values ​​to ($ array[] = $ newvalue), it's time to learn about one more thing … multidimensional arrays.

Multidimensional matrices are matrices with matrices inside them.
We'll see:

tutorial.php

Code:

"Ghost", "age" => 25, "role" => 2, "friends" => array ("Frank", "James", "Chris")); // associative matrix

$ groups = array ("User", "Moderator", "Administrator");
/ *
Yes, numeric arrays do not require that you include the syntax # => in front of each value
You can simply list the values ​​within the matrix, and PHP will automatically apply the keys 0, 1, 2 to our User, Moderator and Administrator values.
* /

$ role = $ info["role"];
echo "{$ info["name"]} is a company {$ groups[$role]} ";
?>

This prints "Ghost is a company administrator". in the page.

As you can see, I made some new things. I did not use the numeric keys in the $ groups array because PHP solves them by default, and I also used the name of $ role in a sentence. I did this because $ role = 2, from the $ info array and $ groups[2]= the name of the group (Administrator). Remember, although we did not supply the numeric keys, PHP automatically made $ groups[0] = "User", 1 = Moderator and 2 = Administrator.

However, the most important thing I did was include a matrix within the matrix. Our "friends" key in the $ info matrix makes our $ info array not only associative, but also a multidimensional matrix. Also, you may have noticed that the $ info[“friends”] that is your own matrix is ​​a numerical matrix.

If we wanted to meet the first friend of this user, we could do …

Code:

echo $ info["friends"][0];

This will print "Frank" on the page because that is key 0 of the friends array: the first result.

Now let's go through our matrix.
We love the loops because they are perfect for repetitive functions. Instead of executing duplicate code for each element of the array, a loop will search all the different values ​​within the array and do things with it. We will go through our array of friends to do things with each other.

tutorial.php

Code:

"Ghost", "age" => 25, "role" => 2, "friends" => array ("Frank", "James", "Chris")); // associative matrix

$ groups = array ("User", "Moderator", "Administrator");
/ *
Yes, numeric arrays do not require that you include the syntax # => in front of each value
You can simply list the values ​​within the matrix, and PHP will automatically apply the keys 0, 1, 2 to our User, Moderator and Administrator values.
* /

$ role = $ info["role"];
echo "{$ info["name"]} is a company {$ groups[$role]} 
"; // FOREACH LOOP foreach ($ info["friends"] like $ friend) { echo $ friend "is a friend of {$ info["name"]}
"; } ?>

In this example we see the following printed on the page.:
Ghost is an administrator of the company.
Frank is a friend of Ghost.
James is a friend of Ghost.
Chris is friends with Ghost.

This is because we use a foreach loop to do the same with each matrix value. We are saying "for each name in the array of friends … do something". Also, the syntax is quite simple, since foreach ($ array as $ variable) is easy to remember.

We could also change foreach to show some keys / matrix labels for values ​​like this … This adds an additional piece to our foreach statement by dividing the key KEY and VALUE. That way we can access the key # or name, and the value separately. It is useful if you need to do something like "if KEY == this, do something different". An example of this would be if you wanted to repeat everything except a matrix value, but in general, you will use most loops when you want to do the same with each value. In general, it will not pass through several matrix values ​​if all of them require a separate logic depending on the key, but there are times when it may be necessary.

Code:




foreach ($ info as $ key => $ value) {
echo "$ key";
}

This would be printed …
"name age role friends", because those are the key names in our matrix. Then, as we separate the key and the value in separate variables in our foreach, we can access both the name of the key and the value itself.

Consider the following …

Code:

"value1", "key2" => "value2");
foreach ($ arr as $ key => $ value) {
echo "The key $ is $ value 
"; } ?>

This shows:
The key1 is value1
The key2 is value2

We can also go through a matrix with a "for loop". It's my favorite type of loop, but it's a bit more complicated. I like the loops because they are very efficient and fast, but foreach can also be good. In fact, I first used foreach and I think it's a good loop to learn at the beginning because it's easy to remember.

We need to know the amount of values ​​within the matrix.

tutorial.php

Code:

"Ghost", "age" => 25, "role" => 2, "friends" => array ("Frank", "James", "Chris")); // associative matrix

$ groups = array ("User", "Moderator", "Administrator");

$ role = $ info["role"];
echo "{$ info["name"]} is a company {$ groups[$role]}, and it's {$ info["age"]year old. 
"; $ num = count ($ info["friends"]); // count the number of values ​​in the matrix info => friends for ($ x = 0; $ x <$ num; $ x ++) { echo $ info["friends"][$x] . "is a friend of {$ info["name"]}
"; } ?>

In this example we see the following printed on the page.:
Ghost is an administrator of the company, and he is 25 years old.
Frank is a friend of Ghost.
James is a friend of Ghost.
Chris is friends with Ghost.

We are going to break the for loop.
We begin by obtaining the value of $ num. It's the number of friends, which is 3.
Then we start our for loop with a new variable that we call $ x.
$ x = 0
Then we say $ x <$ num. This means that our for loop will begin with $ x equal to 0, and will be repeated as long as $ x remains less than (<) $ num or in other words, while $ x is less than 3.

Then we use $ x ++;
This tells our for loop that each time the loop is executed, we want to increase $ x by 1. When you have a number stored in a variable, using $ variable ++ is the same as saying $ variable = $ variable + 1. It simply adds 1 to itself.

Therefore, in our for loop, $ x starts at 0. Each time the loop is executed, it increases by 1, and will continue to loop while $ x is less than $ num (3). So, in this case, the first loop $ x = 0, the second $ x = 1 and the third $ x = 2. After our first 3 loops, $ x would be equal to 3, and the loop stops because our rules they say that the loop should only be executed if $ x is LESS THAN 3, it is not equal to it.

In each of our loops, we access the name of friends with:
$ info[“friends”][$x]

So, our 3 loops are accessing the friend's name in this way:
$ info[“friends”][0]
$ info[“friends”][1]
$ info[“friends”][2]

Because 0, 1, 2 are the values ​​of our variable $ x for our 3 loops
0 refers to the first friend in our $ info[“friends”] array, 1 refers to the second friend and 2 refers to the third friend (because remember, the arrays start at 0 by default for the keys)

You may wonder why we use loops. Well, the loops are perfect for when the amount of information can vary in quantity. If all people have only one age and one name, we do not need to complete the information. However, for things like friends where people can have 0 friends, 3 friends or even hundreds of friends, the loops allow us to execute code for each value in the matrix, regardless of the amount. They can even duplicate each other: a loop inside a loop. This could be taken further to have dozens of nested loops, but there are very few cases where it would be necessary. The loops are good, but they can definitely get out of control.

For large amounts of data, it is important that you do not make your script / page load forever due to a large loop. An example of this would be a forum with 1 million publications in a category. Instead of looping through all 1 million content, we would get the first 25-100 results instead and we would do it. We would pass to the other content if the user went to page 2, for example. Loops are only as good as the programmer, so make sure you're not running unnecessary loops in Big Data unless you really have to.

So let's look at a final example of our for loop, with some matrices.

tutorial.php

Code:

"Ghost", "age" => 25, "friends" => array (array ("name" => "Frank", "age" => 23), array ("name" => "Chris", "age" "=> 26), array (" name "=>" James "," age "=> 27));

$ num = count ($ info["friends"]); // count the number of values ​​in the matrix info => friends
for ($ x = 0; $ x < $num; $x++){ // loop through all the friends results
 // in this example, our friends array actually holds a bunch of separate arrays! 

 if($info["friends"][$x]["age"] > $ info["age"]) {// if our friend's age is greater than ours
$ data[] = $ info["friends"][$x]; // add this friend to the data matrix
}

} // end of for loop

print_r ($ data);
?>

In this last example we are really putting everything together.
We start with an empty matrix, $ data.
We also have our $ info matrix that stores our name, age and our friends. The friends array contains several arrangements, which have information about the friend. When we go through the friends matrix, we can access the information of each friend using the appropriate matrix key (name or age). In this example, we are trying to find all the friends who are older than us. We discovered correctly that Chris and James are older than us, so they are added to the $ data matrix.

The result would be the same as creating the $ data array in this way:

Code:

"Chris", "age" => 26), array ("name" => "James", "age" => 27));
?>

So, as you can see, you can access the data in the matrix with the loop, analyze them and then do things with that information, like building the $ data matrix separately so that only our older friends have it. Obviously, this is a very specific example, but you can do much more, including echo values ​​on the page, trigger another script to execute, or really anything you can imagine.

Python: I get the error false is not true in the django tutorial

I'm following the django tutorial [here][1] https://simpleisbetterthancomplex.com/series/2017/09/25/a-complete-beginners-guide-to-django-part-4.html#testing-the-template-tags.

I am receiving these errors:

==================================================================================================== =====================
FAIL: test_redirection (accounts.tests.test_view_signup.SuccessfulSignUpTests)
-------------------------------------------------- --------------------
Tracking (recent calls latest):
File "C:  Inetpub  wwwroot  myproject2  myproject2  accounts  tests  test_view_signup
.py ", line 50, in test_redirection
self.assertRedirects (self.response, self.home_url)
File "C:  Inetpub  wwwroot  myproject2  venv_two  lib  site-packages  django  test  tes
tcases.py ", line 283, at assertRedirects
% (response.status_code, status_code)
AssertionError: 200! = 302: Response did not redirect as expected: Response code
it was 200 (expected 302)

==================================================================================================== =====================
FAIL: test_user_authentication (accounts.tests.test_view_signup.SuccessfulSignUp
Tests)
-------------------------------------------------- --------------------
Tracking (recent calls latest):
File "C:  Inetpub  wwwroot  myproject2  myproject2  accounts  tests  test_view_signup
.py ", line 63, in test_user_authentication
self.assertTrue (user.is_authenticated)
AssertionError: False is not true

==================================================================================================== =====================
FAIL: test_user_creation (accounts.tests.test_view_signup.SuccessfulSignUpTests)

-------------------------------------------------- --------------------
Tracking (recent calls latest):
File "C:  Inetpub  wwwroot  myproject2  myproject2  accounts  tests  test_view_signup
.py ", line 53, in test_user_creation
self.assertTrue (User.objects.exists ())
AssertionError: False is not true

-------------------------------------------------- --------------------
Ran 29 tests in 1,437s

FAILED (faults = 3, errors = 1)

The problem seems to be on my page test_view_signup.py. Can anyone discern what I have done wrong please?

from django.contrib.auth.models import User
from django.urls import reverse
from django.urls import resolve
from django.test import TestCase

from .. views record views
from ..forms import SignUpForm


SignUpTests class (TestCase):
configuration definition (auto):
url = revert (& # 39; sign up & # 39;)
self.response = self.client.get (url)

def test_signup_status_code (self):
self.assertEquals (self.response.status_code, 200)

def test_signup_url_resolves_signup_view (self):
see = solve (& # 39; / signup / & # 39;)
self.assertEquals (view.func, record)

def test_csrf (self):
self.assertContains (self.response, & # 39; csrfmiddlewaretoken & # 39;)

def test_contains_form (self):
form = self.response.context.get (& # 39; form & # 39;)
self.assertIsInstance (form, SignUpForm)

def test_form_inputs (self):
self.assertContains (self.response, & # 39; <input & # 39 ;, 5)
self.assertContains (self.response, & # 39; type = "text" & # 39 ;, 1)
self.assertContains (self.response, & # 39; type = "email" & # 39 ;, 1)
self.assertContains (self.response, & # 39; type = "password" & # 39 ;, 2)

SuccessfulSignUpTests class (TestCase):
configuration definition (auto):
url = revert (& # 39; sign up & # 39;)
data = {
& # 39; username & # 39 ;: & # 39; john & # 39 ;,
& # 39; password1 & # 39 ;: & # 39; abcdef123456 & # 39 ;,
& # 39; password2 & # 39 ;: & # 39; abcdef123456 & # 39;
}
self.response = self.client.post (url, data)
self.home_url = reverse (& # 39; home & # 39;)

def test_redirection (self):
& # 39; & # 39; & # 39;
A valid form submission should redirect the user to the home page
& # 39; & # 39; & # 39;
self.assertRedirects (self.response, self.home_url)

def test_user_creation (self):
self.assertTrue (User.objects.exists ()) #problem here ???

def test_user_authentication (self):
& # 39; & # 39; & # 39;
Create a new request to an arbitrary page.
The resulting response should now have a `user` in its context,
after a successful registration.
& # 39; & # 39; & # 39;
response = self.client.get (self.home_url)
user = answer.context.get (& # 39; user & # 39;)
self.assertTrue (user.is_authenticated)

InvalidSignUpTests class (TestCase):
configuration definition (auto):
url = revert (& # 39; sign up & # 39;)
self.response = self.client.post (url, {})

def test_signup_status_code (self):
self.assertEquals (self.response.status_code, 200)

def test_form_errors (self):
form = self.response.context.get (& # 39; form & # 39;)
self.assertTrue (form.errors)

def test_dont_create_user (self):
self.assertFalse (User.objects.exists ())

[Tutorial Request] Failover cPanel server configuration

Hi all.

I would like to learn about how to mount a cPanel failover platform. I have experience in the management of cPanel and WHM servers, but without … | Read the rest of http://www.webhostingtalk.com/showthread.php?t=1759720&goto=newpost

Basic JavaScript Tutorial | Promotion Forum

Learning JavaScript is not as difficult as you may think. The language is used for a variety of things on websites, such as changing what visitors see, sending data to another part of your website, temporarily storing user information, validating contact form data, and many other utilities. useful that make the user experience much better. .

In this extremely basic tutorial, you will learn some JavaScript for beginners in relation to the variables and how to display those variables on your website (within HTML). If you want to learn the same in PHP and something else, you can do it with my Basic PHP Tutorial.

If you see something in italics, it is part of our tutorial.html code.

To begin with, we will need an HTML file. For this tutorial, we will do all our coding in a file called & # 39;tutorial.html& # 39; and we will do it do not link to a separate JavaScript file (for example, tutorial.html could be linked to a separate file called tutorial.js).

Create your file called tutorial.html on your desktop You can open it in any web browser you want, and everything will work!

tutorial.html


Our JavaScript starts with the

If you read the comments, now you will know two different ways to declare a string variable in JavaScript, as well as how to declare an integer. However, we do not declare our variables efficiently. There is a much better way to declare multiple variables at once and we will do it now:

tutorial.html

Now you know how to declare multiple variables, and you may have noticed that I used / * and * / within the code. When you use the double bar (//), you are telling JavaScript that you want to have a comment of "one line" or a text that is not a code. Because it is a line, you can not press enter to separate your sentences. With / * and * /, you can have a comment of several lines. JavaScript will ignore all the text within those start / end tags of comments, even if it has several lines separated by blank lines. It's a great way to remember what you're doing, without JavaScript interpreting your comments as code. You can also use it to leave the old code in your script if you want to retrieve it later, or test how a script works with a particular piece of code that is not running. This is useful for proofing errors since you do not have to delete your code, you can only comment on it!

Now, let's learn how to really look at our variables in our browser. There are two ways, but let's start with the easiest way for development. So far, none of our JavaScript is doing anything with our HTML page in our browser, and it should still appear blank for you!

tutorial.html


Once you have configured your console.log () code with its variables inside, you must open tutorial.html in your browser. Next, you should find the & # 39; console log & # 39 ;. In some browsers, by pressing & # 39; ctrl + shift + i & # 39; the console / developer tools registry will open. You can also find them by going to their options menu -> developer tools (or similar). Most likely, your console is a tab on the top of this new panel that will appear on the side (but still inside) of your browser window.

Once you have opened the console registry AFTER you have opened / uploaded tutorial.html, you will see the following (or whatever your variables are configured to be the same):
William
Ghost 25

As you can see, my name is on one line, and my username and my age are on another line. This is due to the two different ways I used console.log () to see my variables! Now let's make the text appear on the page.

tutorial.html

First name:

Username:

Years:


If you did all this correctly, you will notice that not much has happened. Our HTML only shows:
First name:
Username:
Years:

We also remove our original console.log (), so our console.log does not show our variables configured from above. We also added a console.log () below to show us the current values ​​of "innerText" of our sections, to which we point with "document.getElementById ()"

However, we do not have anything within those range values, so the console log only shows a blank line. Let those sections show some content in them!

tutorial.html

First name:

Username:

Years:

Now we can see our information correctly on the HTML page!
Name: william
Username: Ghost
Age: 25

And as our span elements now have values, our console now shows:
William Ghost 25

Therefore, at this point you may be wondering if all this is useful. Well, in this final part of the JavaScript beginner tutorial, I'll show you how to take user input, and show it on the page!

For this part we will use a basic HTML text entry for each entry. We will also add a button that can do things when clicked. Please read the comment carefully ...

tutorial.html

First name:

Username:

Years:


Open your tutorial.html in your browser and click on that button. In your console you will see & # 39; test & # 39; Woo, you created your first button event with central JavaScript! You are doing great :) Now we need to make this really useful. Let's learn how to take those values ​​from those input boxes! Instead of onclick or innerText, we will use the property & # 39; .value & # 39;

tutorial.html

First name:

Username:

Years:

Go ahead and write some things in your input boxes! Each time you press that button, your values ​​provided by the user will be displayed on the console! Woo, we're almost there. Now we are going to make those values ​​appear on the page.

First we will create a span element with the ID & # 39; answer & # 39 ;. Then we'll do something called & # 39; string concatenation & # 39; Basically, this allows us to take JavaScript variables and include them in a sentence or block of text.

It works like this ...
"My variable is equal to ..." + variableHere;
The plus sign allows me to take a string wrapped in double or single quotes and add it.
I can even do it more than once like this ...
var variableHere = & # 39; hello & # 39 ;;
"My variable is equal to ..."
+ variableHere + "... and I love the concatenation of strings!";
This would be the same as:
"My variable equals ... hello ... and I love string concatenation!"

So, let's use a bit of string concatenation in JavaScript to display a message once our user enters their information and click send!

tutorial.html

First name:

Username:

Years:


Open tutorial.html, enter some values ​​and press send!
On my page I see:
Hello William, or should I call you Ghost? Anyway, I see that you are 25 years old.

Congratulations! You have successfully learned how ...

  • Include JavaScript within an HTML file: labels
  • Declare a variable: var variableName = & # 39; something & # 39 ;;
  • Use console console.log ()
  • Stores the text or value of an HTML element: variable = document.getElementById (& # 39; html_id_here & # 39;). innerText (or .value)
  • Change the text / value of an HTML element: document.getElementById (& # 39; html_id_here & # 39;). innerText (or .value) = variableName;
  • Add an event to a button click: document.getElementById ("id"). onclick = function () {// do things}
  • Concatenation strings: "the text can go here" + variableName + anotherVariableName + "more text";

I hope this tutorial has helped you understand JavaScript a little better and I hope you can start creating some great things. With all this knowledge, you can start creating your own basic text RPG, cool forms or even a calculator. Of course, there is more to learn ... You should probably know if there are statements, disinfection of the user's input (making the data is protected against malicious attacks) or validating the input types (example: making sure that something is a number ), but this should help you get started.

If you know someone who wants to learn JavaScript, send them this link.

SQL tutorial for beginners | Promotion Forum

SQL, or structured query language, should interest you if you plan to ever maintain a large community or website. While free web software such as MyBB or payment software such as XenForo will not enter the database, there may be a time when it is not an option. Large forums often have to restructure the web software or the database to make sure it is optimized. For example, the largest MyBB site (HackForums) had problems because its traffic was overloading its servers. Each "search" for information (forum sections, topics, answers, member information, etc.) uses a little bit of resources on the server, and excessive requests can cause a database to run slowly. Therefore, even if you do not want to set up databases for fun or to make a living, I recommend you at least have a basic knowledge of SQL.

In this tutorial we will only focus on real SQL commands. We will not analyze how to actually execute the SQL (with PHP, for example) or show the results of the database on a page for a user. Maybe it will cover more in the future, but you can always see my PHP and SQL tutorial on YouTube! That video will teach you how to use "prepared statements" in PHP to INSERT, DELETE, UPDATE and SELECT data in a database. We will review those concepts here, but only from the perspective of the database!

First let's review what our database will really contain.
For this tutorial, I am using a basic spreadsheet to show you the information, since the format will be the same in several database engines and UI administration tools.

[​IMG]

As you can see, we have a table titled & # 39; content & # 39 ;, with three unique columns (id, title, author).
In SQL, the tables must have a column designated as "unique identifier". This column is our column & # 39; id & # 39 ;. The uniquely identified column acts as a way to access all data efficiently, with a label / ID that can be referenced elsewhere. For example, Content ID 2 is & # 39; Oranges & # 39; for & # 39; Ghost & # 39; I could have a separate table called "Highlights" that stores the content identifiers of all the publications I want to be shown on the cover. In this table you could simply have a column with the tag "content_id" and put "2" there. That would make it easier to get those featured posts out when someone goes to the home page. If you want more information about this specific type of database design, you can always watch my video, How to create and configure relational databases. However, I will discuss the relational tables below when we have our author column use an author ID and configure an author table to store the user's information.

So let's start with our SQL SELECT statements!
A SELECT statement allows us to retrieve data from our table and it looks like this:
SELECT table name columns
That would not work if we just copied and pasted it because "columns" is not a real column name in our table, and our table name is "content", not "table name". So let's reformulate it!
SELECT content title
If we did this, we would receive the following result:
[​IMG]

We can see the "title" column, but nothing else because that is all that we select. Also, because we did not select our column & # 39; id & # 39; (our unique identifier), our database administrator will not allow us to delete or edit any content because it requires a unique identifier to direct the data appropriately. This is not always vital for certain operations, but each table must have a unique ID attached to each row, even if you are not always selecting your own ID column … However, 99.99% of the time you will want to select the ID because of what you are doing with the data.

SELECT ID, title, author FROM content
This SELECT query will search all our columns!
[​IMG]
I have reformatted the names of our columns to make it more obvious that the columns have different configurations. Our column & # 39; id & # 39; is our unique identifier, so it is configured as a "MAIN KEY" column, which is unique. Also, I have set this column to "automatic increment" so that it automatically passes +1 for each new row in the table. This is good because it means that I do not have to worry about inserting a unique ID every time I insert a new row, which we will arrive soon.

In the previous result, we selected the three columns and we saw them all. There is another way in which we can recover the same results …

The * asterisk symbol allows us, basically, to say SELECT * ALL *
SELECT * FROM the content
/ SELECT all of the contents of the table
/ SELECT ID, title, author FROM content

But what if we only want to know the content created by Ghost?
Well, that's easy. We simply use a WHERE statement.

SELECT * FROM the content WHERE author = "Ghost"
[​IMG]

As you can see, it only returned the content created by Ghost.
We could also do the following to find all the content NOT made by Ghost:
SELECT * FROM the content WHERE author! = "Ghost"
[​IMG]

As you can see, it was quite simple. We have the content of Sally.

Well, now is the right time to mention that storing our author's name in our table of contents is a horrible idea. What happens if they change their username? If I do not want to be labeled as 'Phantom', then the database would have to find ALL the places where it says & # 39; Ghost & # 39; and update it … which is very inefficient. Instead, we can have a table to store my username and refer to that table using a user_id. We will also have a relational database.

[​IMG]

In those examples we do some things … On the one hand, the author's column is now "author_id". We also have a table of official authors to store the user / gender information. We go ahead and extract content by author ID instead of by name. We also request a list of all authors who are women. And in the final example, I made a more complicated query that extracts the user name information from each part of the content and shows it along with the title, although now the user name is stored in a separate table. We will not review the UNITE consultations in this tutorial, but I wanted to give you an example of how, even though the data is in a different table, you can still use it for the content of another table.

Okay, so let's go to the INSERT statement. INSERTS are easy and formatted like this …
INSERT INTO table name (column1, column2, column3) VALUES (value1, value2, value)

For example, to create a new author we could do …
Insert in the authors (username, gender) VALUES ("Phil", "masculine")

Or for our content, we could do this:
Insert in the content (title, author_id) VALUES ("Carrot", 2)
That would add a new piece of content called & # 39; Carrot & # 39; by Sally (author_id 2)

[​IMG]

Well, we created a new content and an author.
INSERTS are easy, let's try an UPDATE!

The UPDATE queries allow us to modify the existing information and they look like this …
UPDATE tablename SET column = "value"
That would update each column of a row to equal that value. 99.99% of the time will use a WHERE statement for an UPDATE query.
UPDATE the authors SET username = "William" WHERE id = 1
That would be a query to change the username of the author ID from Ghost to William.

First, I want to replace the words "male" and "female" with whole numbers. I'm going to use 0 for men and 1 for women. This is because I do not want to repeat the words "male" or "female" dozens of times. It takes up more space and can be searched more easily with small digits. You could even add a new digit such as "3" to match something like "Not revealed."

I also want to show you an UPDATE query that could be used if the author edited a part of the content (identified by ID) at a later date. Let's pretend that Sally is updating her article about Carrot …

[​IMG]

As you can see, we made two different update queries to update our gender column and an update query for the content title. The results changed, and we can continue with our day.

Just to remind you, if you do not use a WHERE statement in your update query, you will update EVERYTHING in that table! That can be very bad if it is not intended!

Now let's erase some data!
Remove is also simple …
DELETE FROM table name WHERE column = "value"

Remember to use WHERE because you could eliminate EVERYTHING in the table by simply doing …
DELETE table name

For this, we will pretend that an author has been banned and we want to eliminate all its content.
You can read the notes in the image to see some examples of our process in the database.
[​IMG]
As you can see, we could mark Laura as prohibited, delete her content and then delete her profile when we changed our mind later. Very simple.

That's all there is with SQL for beginners.
You have your INSERT …
Insert in table name (columns, go, here) VALUES ("values", "go", "here")

You SELECT …
SELECT the column, columnTwo FROM tablename WHERE column = "value"
SELECT * FROM tablename

You can UPDATE …
UPDATE tablename SET column = "valueYouWant" WHERE columnTwo = "valueYOuLOOKfor"

and you can DELETE!
DELETE FROM table name WHERE column = "val"

Now he is on track to be able to create or manage his own databases. If you can never imagine yourself doing this, you might be surprised. You may have to modify the way your database works, such as the big MyBB forum that HackForums has to do. You may need to run some queries on your data to discover great trends or market data. There are many good reasons to know SQL (structured query language), especially when the data is increasingly valuable over time. Even if you do not create scripts with PHP to insert / select / update / delete data, it is an impressive skill that can help you in almost any job that uses software to manage the data of your customers / employees / companies. You never know, maybe it's happy, you know!

Thanks for reading my SQL tutorial for beginners.
I hope it was informative and useful. :)

Linux Blackhole Tutorial – Add and delete a null route – Low end box

In the world of system administration, having the commands to add or remove a blackhole / nullroute from a host or a problematic IP address can be very useful. So, in this simple and useful tutorial, we will cover how to do exactly this on almost any type of Linux operating system.

How to add a nullroute black hole:

For this example, suppose we are receiving unwanted SSH session initiation attempts of 192.168.0.195.

root @ server: ~ # netstat -na | grep: 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 192.168.0.197:22 192.168.0.195:57776 ESTABLISHED

To add the black hole to 192.168.0.195:

root @ server: ~ # ip path add black hole 192.168.0.195/32

To verify that the route is in place, "ip route show" will be used:

root @ server: ~ # ip route show
default through 192.168.0.1 dev eth0 metric 100
black hole 192.168.0.195

Subsequently, connections to and from that IP will fail:

root @ attacker: ~ $ ssh 192.168.0.2
ssh: connect to host 192.168.0.2 port 22: there is no route to the host

Eliminating a black hole:

In general, black holes are useful when your server is under attack. After the attack has subsided, or if you want to eliminate the black hole, you can do it as follows:

root @ server: ~ # ip route from 192.168.0.195
root @ server: ~ # ip route show
default through 192.168.0.1 dev eth0 metric 100

Basic PHP tutorial | Promotion Forum

Today I am going to review the most basic PHP so that I can learn how to do several things with the language. This publication covers topics for beginners that can help you get started. I will show you how to store information in your script, display it on the page and configure a basic If / if-else statement. Even if you do not want to learn the language in its entirety, you can help him understand some codes on his current website (forum, blog, etc.) if he uses PHP. This tutorial is very basic, but if you want to know more you can contact me here or contact me on the official website of our company (Wubur). We are a development and marketing company!

First of all, we should review what PHP is mainly used for and what it is for.

  • PHP is a server-side technology, which means that your real server (or server) is running the script
  • For that reason, faster, more efficient and more expensive servers can execute a script better than an older, slower and probably much more affordable server
  • However, PHP is a pretty basic language and good code can be executed quickly and well on almost any web server.
  • PHP can do things like generate blocks of HTML to show on a page, handle things like change what the user sees (requires an update of the page), but it is better to leave them in HTML and JavaScript instead of using the server-side language to manage the visual user's side
  • PHP is an excellent language to learn if you want to store user information in a database or file, allow people to share images / videos / files, allow users to log in to a secure control panel or access functions of the account, selling products online and much more.

There is much more than that, but let's jump to some basic PHP!

We start coding in PHP creating a file that ends with .php (example: index.php)
Even once this is done, we can not open the PHP file with Chrome, Firefox or another Internet browser. This is because PHP is not like HTML / CSS / JavaScript (which are interpreted automatically by web browsers). It is a server-side language, and that means that the server must be configured to run PHP. I will not cover that process in this article. For most of you, if you have a website or plan to have one, you can upload PHP files to your web hosting provider and run them without problems. This is because PHP is used in a large number of web scripts / softwares, including the most famous free and paid forums software available.

If you already have a website and want to follow it, create a folder on your website. Go inside this folder and create the file & # 39; tutorial.php & # 39 ;. Then, in your browser, you can navigate to Your-website.com/folder-name/tutorial.php

Within tutorial.php, we will write all the PHP mentioned below.
You must start a PHP file with the "php tags". This allows the server to know that it is using PHP code. You might think it's obvious because it's a ".php file", but you can still include non-PHP in an .php file. For example, you can use PHP at the top of the file and then HTML at the bottom, or vice versa.

Let's start with that … Anything in italics should be considered PHP code from now on!

tutorial.php
<? php
// opening tag

/ * Now let's write the final tag of php & # 39 ;, which allows our server to know that the php code inside tutorial.php is ending.
It's even simpler than the opening tag! * /
?>
As you can see above, I did some things. I wrote the PHP start tag, and then I used // (double bar).
The double slash is used to initiate a & # 39; comment on a line & # 39 ;. The comment can not be extended to two different lines.

Then down, you can see what I used. / *, which initiates a & # 39; multiline comment & # 39 ;. Then I wrote a couple of sentences on two different lines, and then I finished the comment of several lines with * /
Comments are used to remind you and anyone else working on the script what the code is for. I strongly recommend using comments throughout your code, but remember that having too many comments can often be as bad as not having comments. It should also be borne in mind that companies will sometimes publish their code without comment if they do not want their competition to be easily understood or criticized by competitors. This is the reason why you can see some code without any comments, even if those comments were included in the code when it was being developed.

Now, we have a basic PHP file with the start and end tags, and some comments. Now let's learn how to really configure a variable. A PHP variable is basically like a variable in mathematics. You can say that y = 3, and if you have 2y, it is the same as saying 2 * y, or 2 * 3 (2 multiplied by 3). So, if you said that y = 3, and z = 2y, then z = 6. A variable is just a way of storing information. In PHP you can store many things, but let's start by storing basic numbers and & # 39; chains & # 39 ;. Strings are words or regular text sentences.

tutorial.php
<? php

/ *
Set a variable:
A variable in PHP starts with the dollar sign ($)

You give the variable any name / title / label you want. Variables must start with a letter (a-z) or an underscore (_) and can not include spaces or symbols. For example, $ 1a is not a valid variable, but $ a1 or $ _1a are both valid.

After declaring your variable, use the equal sign (=). After that, you can assign many things, but we will start by simply assigning my name as a string and my age as a number (integer).

After that we need to tell PHP that the line of code is & # 39; made. & # 39; We use a semicolon (;) to allow that to happen. If you forget the semicolon, the PHP script will not work correctly.
* /

$ name = & # 39; William & # 39 ;; // this is a chain
$ username = "Ghost"; // this is also a chain
$ age = 25; // this is an integer

?>

In that example, I showed you how to declare a variable for a string or an integer. I also showed you two ways to declare the chain. You will notice that I use single quotes (& # 39;) to surround my name and double quotes (") to surround my username, both are valid in PHP, and a string should always be in single quotes or double quotes. in the middle of a chain like this: "william". As you can see, I started with a single quote, but I ended up with a double quote. That would cause an error. However, I could do something like this: "william & # 39; s apples": I started and ended with double quotes and, therefore, I was allowed to include a quote within the string without causing an error. With what you start, you must finish with!

Save the code you wrote above and we will add a little more! You can see the final version of this script at the bottom of this article to make sure you have not forgotten anything.
tutorial.php
<? php

// Let's show our variables on the page!
echo $ name;
echo $ age;
echo $ username;

?>

In this example, we use & # 39; eco & # 39 ;. Echo basically tells the script that you want to display the information on the page. If you go to yourwebsite.com/folder/tutorial.php, your script should show your name, age and username. If your variables are NOT declared above the echoes, PHP will not have values ​​to display on the page.

However, there is a "problem" in that example.
With the way I wrote that code, it would show "William25Ghost" because I did not add any space. There are many ways to add space.

tutorial.php
<? php

echo "Example 1: $ name $ age $ username";
echo "
"; // echo to HTML is easy
echo "Example 2:". $ name. "" $ age "" $ username;

?>
In example 1, use double quotes (very important for this example) to include variables within my string that echo.
This is shown on the page: Example 1: William 25 Ghost
If you use single quotes, PHP will not allow you to do that. Basically, when you use double quotes for a string (whether it is declared or echoed), you can place other PHP variables inside it. The following example will show you what is being done.

In example 2, I used something called concatenation. This is when a period (.) Is used to add different variables or strings. I start echoing in "Example 2:" -When I use the later period, basically I say to PHP "And I also miss …". You will see a better example of concatenation below.
This is shown on the page: Example 2: William 25 Ghost

Both examples show the same. You will notice that I also chose to repeat some HTML (a
label) to indicate to the page that shows examples 1 and 2 in two different lines. You can always include valid HTML in your PHP strings to make your content look better. You can have your information echoed by PHP with different fonts, colors, etc. Just make sure that the HTML is valid! Remember, PHP is a server-side code, so using it to design a screen for a user or even adding information to the page is not always sensible. The industry standard is to limit the interaction of PHP with your designs as much as possible and, instead, use PHP to send and retrieve data, while using extremely limited JavaScript or PHP to display it.

tutorial.php
<? php

$ name = "William";
$ username = "Ghost";
$ age = 25;

$ sentence = "The username of $ name is $ username and its age is $ age.";

echo $ phrase
?>
If you go to your tutorial.php page, now you should have a sentence on a line that shows:
William's username is Ghost and his age is 25.

Now that I have shown you how to declare variables and display them on the page, I will show you how to create an "if statement". What this means is that your script asks "if this is true" and, if yes, "do this". There are many ways to configure this, but let's keep a basic if statement for this tutorial.

tutorial.php
<? php
$ name = "William";
$ username = "Ghost";
$ age = 25;
$ lovesPHP = 1;

// our original sentence
$ sentence = "The username of $ name is $ username and its age is $ age.";

// configure an If statement to know if you love PHP or not
yes ($ lovesPHP === 1) {
$ extraSentence = "You love PHP.";
} else {
$ extraSentence = "Does not love PHP.";
}

// repeat our combined complete sentence
echo "Full sentence: $ phrase $ extraSentence";

?>

In this example we see: William's username is Ghost and his age is 25 years. He loves PHP.
If we change $ lovesPHP to equal ANY number other than 1, we would get:
William's username is Ghost and his age is 25. He does not love PHP.

In that statement if we are saying "if the variable $ lovesPHP equals 1 {do this …..} otherwise, do this instead {….}"
You can also do something like this:
<? php

yes ($ lovesPHP === 1) {
$ extraSentence = "You love PHP.";
} else if ($ lovesPHP === 0) {
$ extraSentence = "Does not love PHP.";
} else {
$ extraSentence = "He does not know what PHP is.";
}

// repeat our combined complete sentence
echo "Full sentence: $ phrase $ extraSentence";

?>
In the case, it will only say that I love PHP if $ lovesPHP is equal to 1, I only say no if it is equal to 0, and if it is ANY other number it will say that I do not know what PHP is. As you can see, you can have any number of if statements, else statements, or statements. Else-if basically allows you to verify multiple values ​​or different declarations before going to the capture of all "and if none of that is true, do this"} else {statement. If you do not include the last final statement at the end, that's fine, but you may have problems if another part of your script does not anticipate it. For example, if I do not include that ending} else {, my script would not have access to the variable $ extraSentence because it is not declared, and that would happen if I made $ lovesPHP equal to something other than 0 or 1.

Now, I want to give you a final example of why all this is useful. I will only use the knowledge taught in this mini tutorial, but I hope you get a better idea of ​​how to apply your new skills!

newfile.php
<? php
$ siteOpen = 1;
$ siteName = & # 39; My Site & # 39 ;;
$ siteDesc = & # 39; A description of my site. & # 39 ;;

// now we will finish our php tags to include some HTML after that …
?>


<br /><?php echo $siteName; ?> <br />

<? php

yes ($ siteOpen === 1) {
echo $ siteDesc
} else {
echo "$ siteName is not currently open.";
}

?>

——–
If that is our new file, you will notice that the title of the browser window / tab is the name of our site, and the name of the site is also included on the page in h1 (header tags), with the description below. We also configure an if-else statement to show the description or say that the site is not open. It is not ideal to mix PHP with HTML, but without going into many details, I can not accurately explain the best practices for recovering data with PHP and displaying them on pages. We hope that this last example gives you a good idea of ​​how you can use PHP variables to configure your web pages with HTML templates. For example, a user profile page can rely on ONE version of an HTML design and use PHP to fill that template with data. That way, when you want to redesign the profile page, you will only edit one file instead of having to edit a separate HTML file for each profile page. This is called a dynamic website (not static). Often, the data will be stored in a database, PHP will retrieve that data and set variables for all of them, and then display them within the HTML template.

This is how you have things like? Forum = 63 …
The script says "oh forum = 63, let me extract the data for forum ID 63 from the database … then echo $ forum_name, $ forum_desc, etc. in the forum's HTML visualization template" .

Anyway, this ended up being much longer than anticipated, but I hope it gives you a good idea of ​​how to start learning PHP. It really is a relatively easy language to learn, and it can be very useful to have these tricks up your sleeve.

Here is our finished copy of tutorial.php:

<? php
// always starts with <? php so the server knows that you are running the php code

// let's set some variables:
$ name = & # 39; William & # 39 ;; // this is a string, with single quotes around
$ username = "Ghost"; // This is also a string, with double quotes around it.
$ age = 25; // this is an integer

/ *
Let's show our variables on the page!
this example shows "William25Ghost
* /
echo $ name;
echo $ age;
echo $ username;

echo "


"; // separate example with a line

/ *
Let's echo our variables with some HTML and concatenation below!
court!
* /
echo "Example 1: $ name $ age $ username"; // double quotes allows you to use variables within a string
echo "
"; // echo to HTML is easy
echo "Example 2:". $ name. "" $ age "" $ username; // concatenation (.) allows you to build a chain

echo "


"; // divider

/ *
Let's use the logical statements if, else-if, else to decide which text to show!
* /
yes ($ lovesPHP === 1) {
$ extraSentence = "You love PHP.";
} else if ($ lovesPHP === 0) {
$ extraSentence = "Does not love PHP.";
} else {
$ extraSentence = "He does not know what PHP is.";
}

// repeat our combined complete sentence
echo "Full sentence: $ phrase $ extraSentence";
// You can change the values ​​of $ lovesPHP to see the differences!

?>

You can play with this code to get an idea of ​​how everything works, or even try to add some PHP to your existing web pages! Remember, each PHP page must end in .php, so if you have a file called "home.html", you can convert it to "home.php" to start using PHP inside and expect it to work!

I hope this tutorial has helped you, either from FP or from a search engine. :)

Create Bokeh light effect – Photoshop tutorial

Create Bokeh light effect – Photoshop tutorial

Google Analytics Tutorial

Can someone direct me a good free Google Analytics video tutorial? I would like to learn how to configure it correctly with tags.