Array Exercises and Examples of Arrays using Php

  No comments
Array is a set of variables that have the same data type and are declared with the same name. Array is an important concept in programming, because the array allows to store data and object reference in large quantities and indexed.
The following is an example example of the use of Array, as follows:

Example:
<?php
$year = array(1924, 2010, 2012, 2024, 2050);
echo $year[3];
?>

Example1:
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
echo $student[0]. "<br>";
echo $student[1]. "<br>";
echo $student[2]. "<br>";
echo $student[3]. "<br>";
echo $student[4]. "<br>";
echo $student[5]. "<br>";
?>

Example2:
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
for($x = 0; $x <= 6; $x ++)
{
echo $student[$x]. "<br>";
}
?>

Example3: Array Next
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
For($x = 0; $x <6; $x ++)
{
echo "Index of student array to:" .key($student). "Contains
".current($student)." <br> ";
sext($student);
}
?>

Example3: Array prev
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
End($student);
For($x = 0; $x <6; $x ++)
{
echo "The student array index to:" .key($student). "Contains
".current($student)." <br> ";
Prev($student);
}
?>

Example4: Number of Arrays
<?php
$Student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
$Sumarray = count($student);
echo $sumarray;
?>

Example5: Accessing Arrays In separate variables
<?php
$Student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
List($name, $sex type, $responder, $points, $IP, $specialization) =
$student;
echo $name. "<br>";
echo $jeniskelamin. "<br>";
echo $respon. "<br>";
echo $points. "<br>";
echo $IP. "<br>";
echo $specialization. "<br>";
?>

Example6: Array With Foreach
<?php
$student = array("Eka Haryanto", "Lakilaki", "
11/11/1993 "," B ", 3.41," debageur ");
foreach($student as $datamahasiswa)
{
echo $datamahasiswa. "<br>";
}
?>

Example7: Sort Arrays
<?php
$Data = array(1,3,2,4,7,8,6,5,9,10);
sort($data);
for($x = 0; $x <= 10; $x ++)
{
echo current($data). "<br>";
next($data);
}
?>

Such are examples of the use of arrays, Keep to practice it, Happy coding, and fighting :)

How to Create Flip Text / Upside Down Text

  No comments
Maybe you've seen the status on facebook or tweet on twitter there is writing upside down so it makes more interesting or have never seen at all, then how To make the writing upside down so as to make the status or tweet look more interesting, Here's how to make the writing upside down:

1. Type your writing in the first column (Original)

2. Longer !!! Your writing is automatically reversed in the second column (Reverse / flip)

Original Text:

Fliped text:

Work?

Try to write your comment using reverse writing :D

Search Query with SQL

  No comments

The search system is a system used to search for data that has been stored previously in the database, for a little data may not be necessary, but as more search data is very important to find the data we want, to save time and exact destination / data sought According to what we need, For example: Google, who does not know google? This biggest search engine is one such example, Here are some examples of queries to search:Example 1:
    SELECT table1.field1 FROM table1
    WHERE table1.field1 LIKE "% search%"
    ORDER BY table1.field1 DESC LIMIT 20

In the query "SELECT table1.field FROM table1" so that is shown only field1 in table1 of table1 only to display all the filed can be replaced tabel1.fieldnya with *, then WHERE table1.field1 LIKE "% search%" so with filed1 conditions in table1 We search on the search according to the word we write by replacing the word "search" with the word we want to search, ORDER BY table1.field1 DESC LIMIT 20 sorted by filed1 in table1 by descending (az) with limit displayed / limited by 20 data.But with the query sometimes we use like "% keyword%" is in SQL Statement. What we look for does not appear the example of the scenario, we want to find the top 20 who have the name "eka" because there will be a lot of names, and not to mention the name of the first name or bleakangnya name such as eka haryanto, haryanto eka etc, Finally searched eka does not appear in the top 20 list / top, then the solution using the query model as follows.Example 2:

    SELECT tbl_a.username FROM tbl_a
    WHERE tbl_a._ama_anggota LIKE "% eka%"
    ORDER BY case
    When tbl_a.nama_anggota like "eka" then 1
    When tbl_a.nama_anggota like "eka%" then 2
    When tbl_a.nama_anggota like "% eka" then 3
    Else CONCAT (4, tbl_a.name_members) end LIMIT 20

In the query "SELECT a.name_member FROM tbl_a" so that is displayed only the name of the member in table A of table A only, then WHERE tbl_a.nama_anggota LIKE "% eka%" so with condition nama_anggota in table A that we search on search according to word We write with the word "eka" the word we want to search, then ORDER BY case when tbl_a.nama_anggota like "eka" then 1 when tbl_a.nama_anggota like "eka%" then 2 when tbl_a.nama_anggota like "% eka" then 3 else CONCAT (4, tbl_a.name_members) end LIMIT 20 hereby forces the name of the member whose last name appears at the top followed by the rear variant, the front and the remaining variants, with the limit displayed / limited by 20 data.Thus Query search with SQL there are 2 case examples, where example 1 is a common case example, whereas example2 is a special case example,If any suggestions / maybe there is another statement better please free berargumen but with good manners ya, Happy Coding, And Fighting :)

Examples of Random Functions In PHP

  No comments
The random function is used to randomize a character, to create a random with Integer / Figures type can use the default function of PHP that is with RAND (min, max) as an example:

    <?php
    echo rand (1.10);
    ?>

Then its output is 1-10

But how to make random with letters / alphabets?
The author has not found any special function for random alphabet / letters from PHP, but There are many ways to random functions with these letters / alphabets, including:
Example 1:

    function random ($long) {
       $character = 'ABCDEFGHIJKLMNOPQRSTUabcdefghijklmnopqrstuvwxyz1234567890';
       $String = '';
       For ($i = 0; $i <$long; $i ++) {
           $pos = rand (0, strlen ($character) -1);
           $string. = $Character {$mail};
       }
       return $string;
    }
    echo random (11); // The output of numbers and random letters is 11 characters


 Example 2:

    <?php
    $a1 = str_repeat ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 5);
    $a2 = str_shuffle ($a1);
    echo substr ($a2,0,10); // The output is random numbers and letters of 10 characters
    ?>

 Example 3:

    for ($i = 1; $i <= 10; $i ++) echo chr (rand (97,122));

General Shape and Basic HTML Tag Functions

  No comments
Hyper Text Markup Language (HTML) is a markup language used to create a web page, displaying various information within an Internet browser and formatting simple hypertext written in ASCII format files in order to generate an integrated view of the form. In other words, files are created in word processing software and stored in normal ASCII format so that it becomes a web page with HTML commands. Starting from a widely used language in the publishing and printing world called SGML (Standard Generalized Markup Language), HTML is a widely used standard for displaying web pages. HTML is currently an Internet standard defined and controlled for use by the World Wide Web Consortium (W3C). HTML was created by the collaboration of Caillau TEAM with Berners-lee Robert when they worked at CERN in 1989 (CERN is a high energy physics research institute in Geneva). [Wikipedia], to learn basic HTML you should type in Notepad.


General forms:

<html>
<head>
 <title> Website Title </title>
</head>
<body>
        
It's the page of your site.

         fill
the HTML commands here.
</body>
</html>

When done typing, save with the name example.html remember the extension. Html and on the note pad select All types (*. *). To check it you double click the file you have saved. Actually you can use the .htm extension, but to be the same, you should use the .html extension.

 
Try you type the following HTML commands, then you run in the browser!

<html>
<head>
   <title> My first Training</title>
</head>
<body bg color="#000000">
    <p align="left">
          This paragraph will be flat left <br> <br>

        
<p> br is used to replace lines <br> <br>

        
<b> This sentence will be printed Bold </ b> <br>

        
<i> This sentence will be printed Italic </ i> <br>

        
<b> <i> This sentence will be printed Bold and Italic </ i> </ b>

    <hr width="1000"><br>
 The hr command is used to create lines
 
</body>
</html>

Save your work with the name of example_2.html. If true, the result should be displayed as shown below:



Figure 1.2 Results from example_2.html



Consider the following command:

     <p align = "left">


P in the above command is called tag, while align is called with attribute. The attribute is the command that accompanies the tag.


Here are some HTML commands and their functions:


Tag
Atribut/Contoh penulisan
Fungsi
<body>
<body bgcolor=”red”>
<body bgcolor=”#FF0000”>

text=” ... “ link=” ...” vlink=”...”
alink=”...”

<body
background=”D:\Gambar.jpg”>
Backgorund halaman berwarna merah

Memberi warna pada teks
Warna link
Warna link yang sudah dikunjungi
Warna link yang aktif

Memberi background gambar pada halaman
<a> ... </a>

<a href=”D:\home.html”>Home</a>
<a
href="http://www.yahoo.com/">Ya hoo!</a> <a href="mailto:name@domain.com" >here</a> to email me!
Membuat hyperlink/link

<img>
<img src="person.jpg" width="50" height="50" border="0"
alt="Person" align="left">


Memasukkan gambar dengan nama file gambar person.jpg, lebar 50px, tinggi 50px, border 0, rata kiri, dan jika gambar tidak muncul akan keluar teks Person


<img src=”C:\Documents and
Settings\All Users\Documents\My
Pictures\Sample
Pictures\Sunset.jpg>


<font>... /font>


<FONT size="2" color="#FFFF00" face="arial">...</font>
Mengatur font dengan ukuran 2, warna kuning, jenis huruf Arial
<BIG>...</BIG>
<BIG>Contoh </BIG>
Membuat teks Contoh menjadi lebih besar
<SMALL>...</SMALL>
<SMALL> Contoh</SMALL>
Membuat teks Contoh menjadi
lebih kecil
<b>...</b>
Teks bold/dicetak lebih tebal

<i>…</i>
Teks italic/miring

<strike>...</strike>
Teks tercoret

<u>...</u>
Teks underlined

<h1>...</h1>
Teks heading 1. Tingkat heading bisa sampai tingkat 6. Semakin besar tingkar heading, maka teks aka dicetak semakin kecil

<hr>
<hr width=”600”>




<hr align=”center” size=”5” width=”80%” 
Garis dengan lebar 600. Tag <hr>
tidak perlu ditutup

Garis dengan tinggi 5, lebar 80% dari lebar layar browser dan rata tengah

<p align=”center’> ...
</p>
Paragraf rata tengah. Perintah ini juga dapat ditulis dengan tag
<center>...</center>




<br>
Tag untuk ganti baris
Tag <br> tidak perlu ditutup
<sup>...</sup>
Teks superscript

<sub>...</sub>
Teks subscript

<marquee> .... 
</marquee>
Teks berjalan. Memiliki atribut direction, behavior dan lain-lain.
Contoh:
<marquee direction=”right”>
....</marquee>
<marquee behavior=”alternate”>
... </marquee>





TABLE


Some important commands for creating tables:

1. <table border = "1"> .... </ table> is the main command in the creation of tables, tables with a thickness of 1px

2. <tr> ... </ tr> tag to create a row

3. <td> ... </ td> tag to create a column / cell

4. colspan merge / expand column / cell

5. rowspan merge / widen line


Atribute tabel and fungsions


Tag
Atribut/Contoh penulisan
Fungsi
<table>
...
</table>
border=”...”
Ketebalan tabel.
Contoh:
<table border=”1”>

align=”...”
Pengaturan tabel (rata tengah, kanan atau kiri)

width=”...”
Lebar tabel. Bisa diisi dengan satuan pixel atau persen.
Contoh:
<table width=”80%”> atau
<table width=”600”>

valign=”...”
Perataan secara vertikal dari suatu cell.
(top, middle, bottom)

bordercolor=”...”
Warna border

bgcolor=”...”
Warna      background       tabel,
baris atau cell



In order for the cells in the tabell to be empty, then the command can be used & nbsp;


  So explanation of General Shape and Basic HTML Tag Function, apologize if there is error, easy to be useful, umpteen and thank you.