Kategori
WordPress

Membuat Halaman Statis (Page) dalam WordPress (Beginner Only)

Studi Kasus : Membuat halaman statis (page) di wordpress
Kebutuhan
: just Your WordPress.com Account
Warning : This tutorial is BEGINNER only, so, watch out! 🙂

Halaman statis (page) dalam per-blogging-an dibutuhkan ketika kita ingin membuat suatu halaman yang –well, jelasnya–statis. Berbeda dengan blog post / posting, Page biasanya berisi mengenai halaman – halaman yang hampir tidak pernah / jarang dilakukan update. Lihat gambar dibawah,

Gambar diatas adalah contoh dari Page dalam wordpress.

Untuk membuat halaman statis atau page ini, ikuti langkah – langkah berikut :

Membuat Page
1. Login ke dalam account wordpress dengan username dan password account anda.
2. Anda akan diarahkan ke halaman dashboard.
3. Klik pada menu Page, pada bagian menu samping kiri (sidebar wordpress dashboard). Lihat gambar.

4. Pilih button Add New.
5. Maka anda akan diarahkan pada tampilan halaman posting (mirip seperti ketika kita melakukan posting artikel biasa). Tuliskan isi dari halaman statis yang anda inginkan. Lihat sample dibawah ini.

6. Klik publish untuk menyimpan page anda.

Test : Buka situs wordpress anda. Maka halaman page anda akan muncul. Lihat contoh gambar dibawah.

About this Blog merupakan page yang baru saja dibuat. Page tersebut muncul disamping page default dari wordpress, yaitu Home.

Ingin halaman statis anda muncul pada awal blog anda (sebagai index) ?

Setting Page
Setting ini dilakukan untuk memastikan bahwa halaman statis anda berada dihalaman awal (ketika blog wordpress anda dijalankan – index page). Hal ini berguna, misalkan, anda menginginkan ketika seseorang membuka blog anda, maka akan langsung diarahkan ke halaman About Me.
Dalam kasus ini, anda harus membuat page About Me terlebih dahulu (Lihat step-by-step diatas), kemudian mengatur settingnya. Berikut adalah cara mengatur setting page agar muncul dihalaman awal wordpress.
1. Pilih menu Setting – Reading pada bagian menu samping kiri wordpress.
2. Pada halaman setting Reading, atur seperti gambar dibawah.

3. Simpan setting dengan memilih button Save.

Test : Buka situs wordpress anda sekali lagi. Kali ini, pastikan page yang baru anda buat tertampil sebagai index page 🙂
Lihat gambar.

Happy WordPress-ing 🙂

Kategori
PHP

Code Igniter : Export Data into PDF File

Case Study : Data Export Mysql Database into a PDF file in Code Igniter.
Requirements:
1. Webserver package, already installed.
2. Code Igniter Bundle.
3. Cezpdf library –> download here

Sometimes, when we make an application, we will need to exported data into a pdf file (apart from the excel file), for example to create letters or reports. With a library cezpdf (by Wayne Munro), make a report as a pdf not be too difficult.

A. Preparing Database
1. Create a database with the name db_tutorial.
2. Create a table named tb_member, with the structure of the table below,

3. Insert a few sample data in tb_member, such as the data below,

4. Okay, done with the database.

B. Prepare files and directory structure
1. Install CodeIgniter, by extracting the bundle CI and place it in your document root.
2. Set the database settings (system-config-application-database.php) by setting the database to be used (db name: db_tutorial)
3. Set the url base config (system-config-application-config.php)
4. Put the files cezpdf.php and class.pdf.php (the downloaded library Cezpdf above) in a folder system-application-libraries
5. Put the files in the folder pdf_helper.pdf-helper-application system.
6. Ok: D

C. Make a model
1. Type the following script,
[sourcecode language=”php”]
<?php
class Member_model extends Model {
function Member_Model() {
parent::Model();
}
function alldata()
{
$this->db->select(‘*’);
$this->db->from(‘tb_member’);
$this->db->order_by(‘no’,’ASC’);
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else return null;
}
}
?>
[/sourcecode]
2. Save with the name of the folder system member_model.php-models-application

D. Make Controller
1. Type the following script,
[sourcecode language=”php”]
<?php
class Member_con extends Controller {
public function __construct() {
parent::__construct();
$this->load->model(‘member_model’);
$this->load->helper(‘url’);
}
public function index() {
$data[‘member’] = $this->member_model->alldata();
$this->load->view(‘member_view’, $data);
}

function topdf () {
$this->load->library(‘cezpdf’);
$this->load->helper(‘pdf’);
prep_pdf();
$data[‘member’]= $this->member_model->alldata();
$titlecolumn = array(
‘no’ => ‘no’,
‘name’ => ‘name’,
‘address’ => ‘address’
);
$this->cezpdf->ezTable($data[‘member’], $titlecolumn,’Member Data’);
$this->cezpdf->ezStream();
}
}
?>
[/sourcecode]
2. Save with the name of the folder system member_model.php-models-application

E. Create View
1. Type the following script,
[sourcecode language=”php”]
<h4>Member Data</h4>
<?php if(count($member) > 0) { ?>
<table border="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Address</th>
</tr>
<?php
foreach($member as $rows) {
echo "<tr>";
echo "
<td>". $rows[‘no’]."</td>
<td>". $rows[‘name’] ."</td>
<td>". $rows[‘address’] ."</td>
"; } ?>
</table>
<?php } ?>
<br> <br>
<a href='<?php echo base_url(); ?>index.php/member_con/topdf’><span

style=’color:green;’>Export to Pdf</span></a>
[/sourcecode]
2. Save with the name of the folder system member_model.php-models-application

F. Testing code
1. Open http://localhost/ci_tutor/index.php/member_con. You will see the data that exists in tb_member like the picture below,

2. Click the link export to pdf to export data into pdf file.
3. So automatically your browser (or download manager) will download the pdf file.
4. Open the pdf files, you will see data from tb_member displayed in pdf file:) See the picture below.

Happy coding: D

Kategori
PHP

Code Igniter : Export Data ke File PDF

Studi Kasus : Export Data Mysql Database ke dalam file PDF dalam Code Igniter.
Kebutuhan :
1. Webserver package, already installed.
2. Code Igniter Bundle.
3. Cezpdf library –> download here

Adakalanya, ketika kita membuat aplikasi, kita akan membutuhkan untuk mengexport data ke dalam file pdf (selain dari file excel), misalkan untuk membuat surat atau laporan tertentu. Dengan library cezpdf (karya Wayne Munro ), membuat laporan dalam bentuk pdf tidak akan terlalu sulit.

A. Mempersiapkan Database
1. Buat database dengan nama db_tutorial.
2. Buat tabel dengan nama tb_member, dengan struktur tabel dibawah ini,

3. Insert-kan beberapa sample data dalam tb_member, misal seperti data dibawah ini,

4. Okay, done with database.

B. Mempersiapkan file dan struktur direktori
1. Install Codeigniter, dengan mengekstrak bundle CI dan menempatkannya dalam document root anda.
2. Atur setting database (system-application-config-database.php) dengan setting database yang akan digunakan (db name : db_tutorial)
3. Atur config base url (system-application-config-config.php)
4. Letakkan file cezpdf.php dan class.pdf.php (hasil download Cezpdf library diatas) dalam folder system-application-libraries
5. Letakkan file pdf_helper.pdf dalam folder system-application-helper.
6. Ok 😀

C. Membuat model
1. Ketikkan script berikut ini,
[sourcecode language=”php”]
<?php
class Member_model extends Model {
function Member_Model() {
parent::Model();
}
function alldata()
{
$this->db->select(‘*’);
$this->db->from(‘tb_member’);
$this->db->order_by(‘no’,’ASC’);
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else return null;
}
}
?>
[/sourcecode]
2. Simpan dengan nama member_model.php dalam folder system-application-models

D. Membuat Controller
1. Ketikkan script berikut ini,
[sourcecode language=”php”]
<?php
class Member_con extends Controller {
public function __construct() {
parent::__construct();
$this->load->model(‘member_model’);
$this->load->helper(‘url’);
}
public function index() {
$data[‘member’] = $this->member_model->alldata();
$this->load->view(‘member_view’, $data);
}

function topdf () {
$this->load->library(‘cezpdf’);
$this->load->helper(‘pdf’);
prep_pdf();
$data[‘member’]= $this->member_model->alldata();
$titlecolumn = array(
‘no’ => ‘no’,
‘name’ => ‘name’,
‘address’ => ‘address’
);
$this->cezpdf->ezTable($data[‘member’], $titlecolumn,’Member Data’);
$this->cezpdf->ezStream();
}
}
?>
[/sourcecode]
2. Simpan dengan nama member_model.php dalam folder system-application-models

E. Membuat View
1. Ketikkan script berikut ini,
[sourcecode language=”php”]
<h4>Member Data</h4>
<?php if(count($member) > 0) { ?>
<table border="1">
<tr>
<th>No</th>
<th>Name</th>
<th>Address</th>
</tr>
<?php
foreach($member as $rows) {
echo "<tr>";
echo "
<td>". $rows[‘no’]."</td>
<td>". $rows[‘name’] ."</td>
<td>". $rows[‘address’] ."</td>
"; } ?>
</table>
<?php } ?>
<br> <br>
<a href='<?php echo base_url(); ?>index.php/member_con/topdf’><span

style=’color:green;’>Export to Pdf</span></a>
[/sourcecode]2. Simpan dengan nama member_model.php dalam folder system-application-models

F. Testing code
1. Buka http://localhost/ci_tutor/index.php/member_con. Anda akan melihat data yang ada dalam tb_member seperti gambar dibawah ini,

2. Klik link export to pdf untuk mengeksport data ke dalam file pdf.
3. Maka secara otomatis browser anda (atau download manager) akan men-download file pdf.
4. Buka file pdf, anda akan melihat data dari tb_member tertampil dalam file pdf tersebut 🙂 Lihat gambar dibawah.

Happy coding 😀

Kategori
PHP

String Functions in the PHP

Discussion Board: Introduction to the various functions – the basic string functions (which are often used) in PHP and its possible use.
Kebutuhan : Webserver Package, already installed.

Text is one of the sources of unstructured data is greatest, because most of the information stored in the text, whether text in a variety of filetype (doc txt pdf etc) and web-text (html). Today more often performed research involving the text, and computer science that involves the text of which is the Natural Language Processing, Text (Web) Mining, or Information Retrieval.

Here are some of functions of a text (string) in PHP which will often be used if you are struggling with studies involving text processing.

1. Adding a slash (\) in the string -> addslashes.
[sourcecode language=”php”]
<?php
$text = "This is Anne’s book.";
echo addslashes($text);
?>
[/sourcecode]
Output :
This is Anne\’s book.

Why is this important? In text processing, it is often a sign of the quote (‘) will cause an error when done parsing of the text, especially when we use regular expressions.

2. Breaking the string with the string -> explode.
[sourcecode language=”php”]
<?php
$sentence = "My name is June";
$word = explode(" ", $sentence);
print_r($word);
?>
[/sourcecode]
Output :
Array
(
[0] => My
[1] => name
[2] => is
[3] => June
)

Explode will break up the text and divide it into an array, like the example above, $text in-explode with the string “” (space). This is the basis of tokenizing algorithm, namely breaking the sentence in the word – the word constituent. Tokenizing will often be used in text processing.

3. Combining an array of strings in one string -> implode.
[sourcecode language=”php”]
<?php
$arrayWord = array(‘This’, ‘is’, ‘a’, ‘sentence’);
$joinString = implode(" ", $arrayWord);
echo $joinString;
?>
[/sourcecode]
Output :
This is a sentence

Implode, as seen from the example above (example: arrays in the sample-implode / merged by using the string space), is the opposite of the function No. 2 (explode). Implode function has an alias, which is Join.

4. Provides MD5 value from string -> md5.
[sourcecode language=”php”]
<?php
$string = ‘password’;
$stringMd5 = md5($string);
echo $stringMd5;
?>
[/sourcecode]
Output :
5f4dcc3b5aa765d61d8327deb882cf99

MD5 is a hash function (cryptographic one-way) is quite well known and often used for security (although it’s a lot md5 decryptor). Md5 function like this will often be used when we build an application that requires authentication (eg to log into the system).

5. Removes HTML tags in the string -> strip_tags
[sourcecode language=”php”]
<?php
$text = ‘<b>June Susan</b> <i> June June</i>’;
echo strip_tags($text); echo ‘<br>’;
echo strip_tags($text, ‘<i>’); // Allow tag <i>
?>
[/sourcecode]
Output :
June Susan June June

Before we can process the text from the web (which is usually in the form of hypertext / html), then we must be “clean” tag – html tags that exist in the text. This is where the strip_tags function is useful. We can remove all tags, or allow certain tags to remain in the text (see examples).

6. Calculating the length of string -> strlen.
[sourcecode language=”php”]
<?php
$string = ‘I am a superman’;
echo strlen($string);
?>
[/sourcecode]
Output :
15

Strlen count the number of characters (length) of the string, spaces, and symbols – symbols that exist in the string will also be calculated in function strlen.

Happy coding, then! 😀

Kategori
PHP

Fungsi – Fungsi String dalam PHP

Discussion Board : Pengenalan berbagai fungsi – fungsi String dasar (yang sering digunakan) dalam PHP beserta contoh penggunaannya.
Kebutuhan : Webserver Package, already installed.

Text adalah salah satu sumber unstructured data yang paling besar, karena sebagian besar informasi tersimpan dalam text, baik text dalam berbagai filetype (doc txt pdf dll) maupun web text (html). Dewasa ini semakin sering dilakukan riset yang melibatkan text, dan bidang ilmu komputer yang melibatkan text diantaranya adalah Natural Language Processing, Text (Web) Mining, ataupun Information Retrieval.

Berikut adalah beberapa fungsi text (string) dalam PHP yang akan sering digunakan apabila anda berkutat dengan penelitian yang melibatkan text processing.

1. Menambahkan slash (\) dalam string –> addslashes.
[sourcecode language=”php”]
<?php
$text = "This is Anne’s book.";
echo addslashes($text);
?>
[/sourcecode]
Output :
This is Anne\’s book.

Kenapa hal ini penting? Dalam pemrosesan teks, seringkali tanda quote (‘) akan menimbulkan eror ketika dilakukan parsing terhadap text tersebut, terutama ketika kita menggunakan regular expression.

2. Memecah string dengan string –> explode.
[sourcecode language=”php”]
<?php
$sentence = "My name is June";
$word = explode(" ", $sentence);
print_r($word);
?>
[/sourcecode]
Output :
Array
(
[0] => My
[1] => name
[2] => is
[3] => June
)

Explode akan memecah text dan membaginya ke dalam array, seperti contoh diatas, $text di-explode dengan string ” ” (spasi). Hal ini merupakan dasar dari algoritma tokenizing, yaitu memecah kalimat dalam kata – kata penyusunnya. Tokenizing akan sering sekali digunakan dalam text processing.

3. Menggabungkan array string dalam satu string –> implode.
[sourcecode language=”php”]
<?php
$arrayWord = array(‘This’, ‘is’, ‘a’, ‘sentence’);
$joinString = implode(" ", $arrayWord);
echo $joinString;
?>
[/sourcecode]
Output :
This is a sentence

Implode, seperti terlihat dari contoh diatas (contoh : array dalam contoh di-implode / digabung dengan menggunakan string spasi), merupakan kebalikan dari fungsi no 2 (explode). Fungsi implode memiliki alias, yaitu Join.

4. Memberikan nilai MD5 dari string –> md5.
[sourcecode language=”php”]
<?php
$string = ‘password’;
$stringMd5 = md5($string);
echo $stringMd5;
?>
[/sourcecode]
Output :
5f4dcc3b5aa765d61d8327deb882cf99

MD5 merupakan salah satu fungsi hash (kriptografi satu arah) yang cukup terkenal dan sering digunakan untuk security (meskipun sekarang sudah banyak md5 decryptor). Fungsi md5 seperti ini akan sering digunakan apabila kita membangun sebuah aplikasi yang memerlukan autentikasi (misal untuk login ke dalam sistem).

5. Menghilangkan HTML Tag dalam string –> strip_tags
[sourcecode language=”php”]
<?php
$text = ‘<b>June Susan</b> <i> June June</i>’;
echo strip_tags($text); echo ‘<br>’;
echo strip_tags($text, ‘<i>’); // Allow tag <i>
?>
[/sourcecode]
Output :
June Susan June June

Sebelum kita bisa memproses text dari web (yang biasanya berbentuk hypertext / html), maka kita harus “membersihkan” tag – tag html yang ada dalam text tersebut. Disinilah fungsi strip_tags berguna. Kita bisa menghilangkan seluruh tag, ataupun mengijinkan tag tertentu untuk tetap berada dalam text (lihat contoh).

6. Menghitung panjang string –> strlen.
[sourcecode language=”php”]
<?php
$string = ‘I am a superman’;
echo strlen($string);
?>
[/sourcecode]
Output :
15

Strlen menghitung jumlah karakter (panjang) dari string, spasi, dan simbol – simbol yang ada dalam string juga akan dihitung dalam fungsi strlen.

Happy coding, then! 😀

Kategori
PHP

Get the Data from Database with Codeigniter and Show it with JQuery UI Tab

Studi Kasus : Read data from the database, show it in the JQuery UI Tab with AJAX.
Kebutuhan : Webserver package already installed.
File Download: 1. CodeIgniter. 2. JQuery. 3. JQuery UI If you’ve never used this UI, just download a theme that already exist without the customized first. 4. Mic JQuery Template Plugin.
Special Skill : PHP. Codeigniter.

A. Prepare the Database
1. Create a database with the name db_tutorial.
2. Create a table named tb_book, with the structure of the table below,

3. Insert some sample data into tb_book.
4. Again create a table named tb_member, with the structure of the table below,…

5. Insert some sample dta into tb_member.
6. Okay, done with database.

B. Prepare job folders and files – the files needed.
1. Prepare a folder with the name ci_tutor in your document root.
2. CodeIgniter extract in the folder you just created (here user_guide file in my CI delete), and set its cover base_url config, as well as the configuration database in system-config-application-database.php
3. Create a table named cssjs, then put your jQuery file (download file 2) jQuery UI (the downloaded file 3: I choose the template flickr), and files Mic jQuery Plugin Template (file 4) into the folder cssjs.
4. Ci_tutor folder structure is like this,

5. The cssjs folder’s structure is like picture below,

C. Model
1. We will create a model that will take all the data available in tb_book and tb_member. Type the following script,

[sourcecode language=”php”]
<?php
class Book_model extends Model {

public function getBook() {
$query = $this->db->get( ‘tb_book’ );
if( $query->num_rows() > 0 ) {
return $query->result();
} else {
return array();
}
}

public function getMember() {
$query = $this->db->get( ‘tb_member’ );
if( $query->num_rows() > 0 ) {
return $query->result();
} else {
return array();
}
}
}
?>
[/sourcecode]

2. Save with the name book_model.php save into system-application-models.

D. Controller
1. Type the following script,

[sourcecode language=”php”]
<?php
class Book_con extends Controller {
public function __construct() {
parent::__construct();
$this->load->model(‘book_model’);
}
public function index() {
$this->load->view(‘book_view’);
}
public function readBook() {
echo json_encode( $this->book_model->getBook() );
}
public function readMember() {
echo json_encode( $this->book_model->getMember() );
}
}
?>
[/sourcecode]

2. Save with the name book_con.php save into system-application-controllers.

E. View
1. Type the following script,

[sourcecode language=”php”]
<html>
<head>
<title>ITX.WEB.ID</title>
<base href="<?php echo base_url(); ?>" />
<link type="text/css" rel="stylesheet" href="cssjs/flick/jquery-ui-1.8.2.custom.css" />
<link type="text/css" rel="stylesheet" href="cssjs/styles.css" />
</head>
<body>
<center><h2> Book & Member List</h2></center>
<div id="tabs">

<ul>
<li><a href="#read">Book List</a></li>
<li><a href="#read2">Member List</a></li>
</ul>

<div id="read">
<table id="tabel"></table>
</div>

<div id="read2">
<table id="tabel2"></table>
</div>

</div>

<script type="text/javascript" src="cssjs/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="cssjs/jquery-ui-1.8.2.min.js"></script>
<script type="text/javascript" src="cssjs/jquery-templ.js"></script>

<script type="text/template" id="readTemp">
<tr>
<td>${id}</td>
<td>${title}</td>
<td>${author}</td>
</tr>

</script>

<script type="text/template" id="readTemp2">
<tr>
<td>${no}</td>
<td>${name}</td>
<td>${address}</td>
</tr>

</script>

<script type="text/javascript" src="cssjs/all.js"></script>
</body>
</html>
[/sourcecode]

2. Save with the name book_view.php save into system-application-views.

F. Create Javascript file that will read table records from sever with Ajax.
1. Type the following script,

[sourcecode language=”javascript”]
$( function() {
$( ‘#tabs’ ).tabs({
fx: { height: ‘toggle’, opacity: ‘toggle’ }
});

$.ajax({
url: ‘index.php/book_con/readBook’,
dataType: ‘json’,
success: function( response ) {
$( ‘#readTemp’ ).render( response ).appendTo( "#tabel" );
}
});

$.ajax({
url: ‘index.php/book_con/readMember’,
dataType: ‘json’,
success: function( response ) {
$( ‘#readTemp2’ ).render( response ).appendTo( "#tabel2" );
}
});

});
[/sourcecode]

2. Save with the name all.js and save into cssjs folder.

G. Arrange the view
1. Type the following script and save with the name style.css

[sourcecode language=”css”]
body {
font-family: Arial, Helvetica, sans-serif;
}

#tabs {
font-size: .9em;
margin: 0 auto;
width: 800px;
}

.ui-widget-content {
font-size: .8em;
}

#tabel, #tabel2 {
font-size: 1.3em;
width: 100%;
}

#tabel tr:nth-child(2n) {
background: #EAEAEA;
}

#tabel tr:hover {
background: #CCCCCC;
}

#tabel td {
padding: 6px;
margin: 8px;
}
[/sourcecode]

H. Testing code
1. Go to the browser, and run http://localhost/ci_tutor/index.php/book_con/
2. If successful, you will see picture below.

3. Click on the Member List tab, so it will display member data from tb_member.

4. Be creative with another Jquery UI 😀

Happy coding 😀

Kategori
PHP

Menampilkan Data dari Database dengan CodeIgniter + AJAX dalam Template JQuery UI

Studi Kasus : Membaca data dari database, menampilkan dalam JQuery UI Tab dengan AJAX.
Kebutuhan : Webserver package already installed.
File Download: 1. CodeIgniter. 2. JQuery. 3. JQuery UI Kalau belum pernah menggunakan UI ini, download saja tema yang sudah ada tanpa customize dulu. 4. Mic JQuery Template Plugin.
Skill khusus : PHP. Codeigniter.

A. Mempersiapkan Database
1. Buat database dengan nama db_tutorial.
2. Buat tabel dengan nama tb_book, dengan struktur tabel dibawah ini,

3. Insert-kan beberapa sample data dalam tb_book.
4. Buat tabel lagi dengan nama tb_member, dengan struktur tabel dibawah ini,

5. Insert-kan beberapa sample data dalam tb_member.
6. Okay, done with database.

B. Mempersiapkan folder kerja dan file – file yang dibutuhkan.
1. Persiapkan folder dengan nama ci_tutor dalam document root anda.
2. Ekstrak codeigniter dalam folder yang baru saja dibuat (disini file user_guide dalam CI saya hapus), dan atur config nya meliputi base_url, serta konfigurasi database dalam system-application-config-database.php
3. Buat tabel dengan nama cssjs, kemudian taruh file JQuery (file download 2) JQuery UI (hasil download file 3 : saya memilih template flickr), dan file Mic JQuery Template Plugin (file 4) ke dalam folder cssjs.
4. Struktur folder ci_tutor adalah seperti ini,

5. Struktur folder cssjs adalah seperti ini,

C. Model
1. Kita akan membuat model yang akan mengambil seluruh data yang ada dalam tb_book dan tb_member. Ketikkan script dibawah ini,

[sourcecode language=”php”]
<?php
class Book_model extends Model {

public function getBook() {
$query = $this->db->get( ‘tb_book’ );
if( $query->num_rows() > 0 ) {
return $query->result();
} else {
return array();
}
}

public function getMember() {
$query = $this->db->get( ‘tb_member’ );
if( $query->num_rows() > 0 ) {
return $query->result();
} else {
return array();
}
}
}
?>
[/sourcecode]

2. Simpan dengan nama book_model.php dan simpan dalam system-application-models.

D. Controller
1. Ketikkan script dibawah ini,

[sourcecode language=”php”]
<?php
class Book_con extends Controller {
public function __construct() {
parent::__construct();
$this->load->model(‘book_model’);
}
public function index() {
$this->load->view(‘book_view’);
}
public function readBook() {
echo json_encode( $this->book_model->getBook() );
}
public function readMember() {
echo json_encode( $this->book_model->getMember() );
}
}
?>
[/sourcecode]

2. Simpan dengan nama book_con.php dan simpan dalam system-application-controllers.

E. View
1. Ketikkan script dibawah ini,

[sourcecode language=”php”]
<html>
<head>
<title>ITX.WEB.ID</title>
<base href="<?php echo base_url(); ?>" />
<link type="text/css" rel="stylesheet" href="cssjs/flick/jquery-ui-1.8.2.custom.css" />
<link type="text/css" rel="stylesheet" href="cssjs/styles.css" />
</head>
<body>
<center><h2> Book & Member List</h2></center>
<div id="tabs">

<ul>
<li><a href="#read">Book List</a></li>
<li><a href="#read2">Member List</a></li>
</ul>

<div id="read">
<table id="tabel"></table>
</div>

<div id="read2">
<table id="tabel2"></table>
</div>

</div>

<script type="text/javascript" src="cssjs/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="cssjs/jquery-ui-1.8.2.min.js"></script>
<script type="text/javascript" src="cssjs/jquery-templ.js"></script>

<script type="text/template" id="readTemp">
<tr>
<td>${id}</td>
<td>${title}</td>
<td>${author}</td>
</tr>

</script>

<script type="text/template" id="readTemp2">
<tr>
<td>${no}</td>
<td>${name}</td>
<td>${address}</td>
</tr>

</script>

<script type="text/javascript" src="cssjs/all.js"></script>
</body>
</html>
[/sourcecode]

2. Simpan dengan nama book_view.php dan simpan dalam system-application-views.

F. Membuat file Javascript yang akan membaca record tabel dari server dengan AJAX.
1. Ketikkan script dibawah ini,

[sourcecode language=”javascript”]
$( function() {
$( ‘#tabs’ ).tabs({
fx: { height: ‘toggle’, opacity: ‘toggle’ }
});

$.ajax({
url: ‘index.php/book_con/readBook’,
dataType: ‘json’,
success: function( response ) {
$( ‘#readTemp’ ).render( response ).appendTo( "#tabel" );
}
});

$.ajax({
url: ‘index.php/book_con/readMember’,
dataType: ‘json’,
success: function( response ) {
$( ‘#readTemp2’ ).render( response ).appendTo( "#tabel2" );
}
});

});
[/sourcecode]

2. Simpan dengan nama all.js dan simpan dalam folder cssjs.

G. Mengatur tampilan
1. Ketik script berikut ini dan simpan dengan nama style.css

[sourcecode language=”css”]
body {
font-family: Arial, Helvetica, sans-serif;
}

#tabs {
font-size: .9em;
margin: 0 auto;
width: 800px;
}

.ui-widget-content {
font-size: .8em;
}

#tabel, #tabel2 {
font-size: 1.3em;
width: 100%;
}

#tabel tr:nth-child(2n) {
background: #EAEAEA;
}

#tabel tr:hover {
background: #CCCCCC;
}

#tabel td {
padding: 6px;
margin: 8px;
}
[/sourcecode]

H. Testing code
1. Pergi ke browser, dan jalankan http://localhost/ci_tutor/index.php/book_con/
2. Jika sukses, anda akan melihat tampilan di bawah ini.

3. Klik pada tab Member List, maka akan ditampilkan data member dari dalam tb_member

4. Silahkan berkreasi dengan JQuery UI yang lain 😀

Happy coding 😀

Kategori
PHP

Round Number in PHP

Discussion Board : One of the important functions in the mathematical calculations, that do rounding numbers with PHP
Requirements : Webserver package, already installed.

One friend who is building an ecommerce never ask something like this: “How can I create a program that, items weighing less than 1 kg to 1 kg is considered 1 kg, then more than 1 kg to 2 kg is considered 2 kg, and so on? “
The problem above can be written as follows:
1> = weight> 0 —> considered to be 1 kg
2> weight => 1 —> 2 kg is considered
etc. ..

Actually, this problem is not a complex problem. Absolutely not complicated in fact. Examples of the above case is just one example of cases that can be resolved easily by Rounding. In PHP, the known three mathematical functions that can be used for rounding, namely ceil, Floor, and Round.

1. Rounding upwards (ceil).
For example for the above case

[sourcecode language=”php”]
<?php
$berat1 = 0.5;
$berat2 = 1.5;
$berat3 = 2;
echo ‘berat 1 =’.ceil($berat1); echo ‘<br />’;
echo ‘berat 2 =’.ceil($berat2); echo ‘<br />’;
echo ‘berat 3 =’.ceil($berat3);
?>
[/sourcecode]

If the script above is executed, then the output is as follows,
berat 1 = 1
berat 2 = 2
berat 3 = 2
So the conclusion is that the PHP function ceil will perform rounding upwards on the given number. This function will produce the nearest integer value of upwards of a number.

2. Rounding down (floor).
Floor used for rounding down. See the example below,

[sourcecode language=”php”]
<?php
$berat1 = 0.5;
$berat2 = 1.5;
$berat3 = 2;
echo ‘berat 1 =’.floor($berat1); echo ‘<br />’;
echo ‘berat 2 =’.floor($berat2); echo ‘<br />’;
echo ‘berat 3 =’.floor($berat3);
?>
[/sourcecode]

If the script above is executed, then the output is as follows,
berat 1 = 0
berat 2 = 1
berat 3 = 2
Contrary to ceil, the floor will do the rounding to the nearest integer value down of a number.

3. Rounding to the nearest
ROUND round a number to the nearest value in accordance with the number behind the comma deciman desired. For example,

[sourcecode language=”php”]
<?php
$berat1 = 0.58989;
$berat2 = 1.6;
$berat3 = 2.4;
echo ‘berat 1 =’.round($berat1, 2); echo ‘<br />’; // with 2 decimal
echo ‘berat 2 =’.round($berat2, 0); echo ‘<br />’; // 0 decimal
echo ‘berat 3 =’.round($berat3); // without parameter, so it will rounded in to the nearest integer
?>
[/sourcecode]

If the script above is executed, then the output is as follows,
berat 1 = 0.59
berat 2 = 2
berat 3 = 2

Hope it hels! 😀 Happy coding 😀

Kategori
PHP

Pembulatan Bilangan dalam PHP

Discussion Board : Salah satu fungsi penting dalam perhitungan matematika, yaitu melakukan pembulatan angka dengan PHP
Requirements : Webserver package, already installed.

Salah seorang teman yang sedang membangun sebuah ecommerce pernah bertanya seperti ini : “Bagaimana saya bisa membuat program bahwa, barang yang beratnya kurang dari 1 kg sampai 1 kg dianggap 1 kg, kemudian lebih dari 1 kg sampai 2 kg dianggap 2 kg, dan seterusnya?”
Masalah diatas dapat dituliskan seperti berikut :
1 >= berat > 0 —> dianggap 1 kg
2 >= berat > 1 —> dianggap 2 kg
dst..

Sebenarnya, masalah diatas bukanlah masalah yang rumit. Sama sekali tidak rumit malah. Contoh kasus diatas hanyalah salah satu contoh kasus yang bisa diselesaikan dengan mudah dengan Pembulatan. Dalam PHP, dikenal 3 fungsi matematika yang dapat digunakan untuk pembulatan, yaitu Ceil, Floor, dan Round.

1. Pembulatan keatas (Ceil).
Misalnya untuk kasus diatas

[sourcecode language=”php”]
<?php
$berat1 = 0.5;
$berat2 = 1.5;
$berat3 = 2;
echo ‘berat 1 =’.ceil($berat1); echo ‘<br />’;
echo ‘berat 2 =’.ceil($berat2); echo ‘<br />’;
echo ‘berat 3 =’.ceil($berat3);
?>
[/sourcecode]

Kalau script diatas dijalankan, maka outputnya adalah sebagai berikut,
berat 1 = 1
berat 2 = 2
berat 3 = 2
Jadi kesimpulannya adalah, fungsi PHP ceil akan melakukan pembulatan keatas pada angka yang diberikan. Fungsi ini akan menghasilkan nilai integer terdekat keatas dari angka.

2. Pembulatan kebawah (floor).
Floor digunakan untuk melakukan pembulatan ke bawah. Lihat contoh dibawah ini,

[sourcecode language=”php”]
<?php
$berat1 = 0.5;
$berat2 = 1.5;
$berat3 = 2;
echo ‘berat 1 =’.floor($berat1); echo ‘<br />’;
echo ‘berat 2 =’.floor($berat2); echo ‘<br />’;
echo ‘berat 3 =’.floor($berat3);
?>
[/sourcecode]

Script diatas akan menghasilkan output,
berat 1 = 0
berat 2 = 1
berat 3 = 2
Berkebalikan dengan ceil, floor akan melakukan pembulatan ke nilai integer terdekat kebawah dari suatu bilangan.

3. Pembulatan ke terdekat
ROUND membulatkan suatu bilangan ke nilai terdekatnya sesuai dengan jumlah deciman dibelakang koma yang diinginkan. Sebagai contoh,

[sourcecode language=”php”]
<?php
$berat1 = 0.58989;
$berat2 = 1.6;
$berat3 = 2.4;
echo ‘berat 1 =’.round($berat1, 2); echo ‘<br />’; // with 2 decimal
echo ‘berat 2 =’.round($berat2, 0); echo ‘<br />’; // 0 decimal
echo ‘berat 3 =’.round($berat3); // without parameter, so it will rounded in to the nearest integer
?>
[/sourcecode]

Jika dijalankan, maka script akan memberi output :
berat 1 = 0.59
berat 2 = 2
berat 3 = 2

Semoga membantu 😀 Happy coding 😀

Kategori
WordPress

Put Flickr Album Photos in to WordPress

Discussion Board : Put Ur Flickr Photo Album in to wordpress widget.
Kebutuhan : WordPress.com Account, or CMS WordPress that have been installed in the server.

If U are such a fan of photography, U must be knew of FLICKR. Yeah, Flickr is one of the photo sharing services that quite popular from Yahoo!
U can access flickr through the site www.flickr.com, and if U already have a yahoo account, U can use it for login in to Flickr with that yahoo account. Except Flickr, there are another photo sharing services such as photobucket.

On WordPress, we can put our photo album on the wordpress page using widget. Widgets, in the wordpress, is located on the sidebar of Ur wordpress page, usually in the right or left side, sometimes on the behind above the footer wordpress page. For this case study, we will try to put the flickr photo album in the wordpress page.

Case study : Put Flickr Photo Album in the WordPress widgets.
Assumptions : U already have Flickr account, and there is some photos there in Ur flickr (You have to upload the photo in the flickr for the sample).

The steps :
1. Login in to Ur wordpress account.
2. From the dashboard, go to the Appearance – Widgets menu.
3. You will find list of available widget. Drag flickr widget Flickr in to thesidebar (right side of the widget page), so the setting for flickr is opened like the picture below.

Fill the detail of the flickr feed that u want to showed (like the picture above). For the flickr address (Flickr RSS URL), U can get it from the flickr page, the corner-left-under with the RSS symbol.
4. Save setting for flickr.
5. Go to your wordpress site. Your Flickr album photo is already showed according to your setting (you can customize the number of the photo thumbnailed) 😀 The picture below is a sample of the Flickr album photo in the wordpress page sidebar.

Beautiful, right? 😀 Okay, happy WordPress-ing 😀
And Take a lot on your camera !