<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tutorial Melayu &#187; php</title>
	<atom:link href="http://www.tutorialmelayu.com/category/web-programming/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.tutorialmelayu.com</link>
	<description></description>
	<lastBuildDate>Sun, 06 Nov 2011 12:38:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Menggunakan PHP CLI di dalam Windows</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/menggunakan-php-cli-di-dalam-windows</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/menggunakan-php-cli-di-dalam-windows#comments</comments>
		<pubDate>Sun, 26 Dec 2010 01:50:16 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[cakephp bake]]></category>
		<category><![CDATA[php cli]]></category>
		<category><![CDATA[php.exe]]></category>
		<category><![CDATA[yiic]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=361</guid>
		<description><![CDATA[Jika anda mahu menggunakan PHP CLI untuk: Bake dengan CakePHP atau menggunakan Yiic dengan Yii atau apa-apa sahaja command yang melibatkan php.exe --------------------------------------------------------------- App : app Path: /path-to/project/app --------------------------------------------------------------- Interactive Bake Shell --------------------------------------------------------------- &#91;D&#93;atabase Configuration &#91;M&#93;odel &#91;V&#93;iew &#91;C&#93;ontroller &#91;P&#93;roject &#91;Q&#93;uit What would you like to Bake? &#40;D/M/V/C/P/Q&#41; &#62; YiiRoot/framework/yiic webapp demo Create a Web application [...]]]></description>
			<content:encoded><![CDATA[<p>Jika anda mahu menggunakan PHP CLI untuk:</p>
<ul>
<li>Bake dengan CakePHP</li>
<li>atau menggunakan Yiic dengan Yii</li>
<li>atau apa-apa sahaja command yang melibatkan php.exe</li>
</ul>

<div class="wp_codebox"><table><tr id="p3615"><td class="code" id="p361code5"><pre class="dos" style="font-family:monospace;">---------------------------------------------------------------
App : <span style="color: #b100b1; font-weight: bold;">app</span>
Path: /path-to/project/app
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
<span style="color: #66cc66;">&#91;</span>D<span style="color: #66cc66;">&#93;</span>atabase Configuration
<span style="color: #66cc66;">&#91;</span>M<span style="color: #66cc66;">&#93;</span>odel
<span style="color: #66cc66;">&#91;</span>V<span style="color: #66cc66;">&#93;</span>iew
<span style="color: #66cc66;">&#91;</span>C<span style="color: #66cc66;">&#93;</span>ontroller
<span style="color: #66cc66;">&#91;</span>P<span style="color: #66cc66;">&#93;</span>roject
<span style="color: #66cc66;">&#91;</span>Q<span style="color: #66cc66;">&#93;</span>uit
What would you like to Bake? <span style="color: #66cc66;">&#40;</span>D/M/V/C/P/Q<span style="color: #66cc66;">&#41;</span> 
&gt;</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p3616"><td class="code" id="p361code6"><pre class="dos" style="font-family:monospace;">YiiRoot/framework/yiic webapp demo
Create a Web application under '/Webroot/demo'? <span style="color: #66cc66;">&#91;</span>Yes|No<span style="color: #66cc66;">&#93;</span>
Yes
<span style="color: #b1b100; font-weight: bold;">mkdir</span> /WebRoot/demo
<span style="color: #b1b100; font-weight: bold;">mkdir</span> /WebRoot/demo/assets
<span style="color: #b1b100; font-weight: bold;">mkdir</span> /WebRoot/demo/css</pre></td></tr></table></div>

<p>Perkara pertama yang perlu dilakukan adalah mencari path kepada php.exe. Untuk instalasi Xampp saya, php.exe terletak di C:/xampp/php/. Jika anda tidak menggunakan xampp, php.exe anda berkemungkinan besar terletak pada path yang berlainan.</p>
<p><strong>Untuk Windows 7</strong>, pergi ke Control Panel / System / Advanced System Setting / Environment Variables. </p>
<p><strong>Untuk Windows XP</strong>, pergi ke Control Panel / System / Advanced / Environment Variables.</p>
<p>Atau anda boleh terus right click pada My Computer dan tekan Properties (untuk Win7 dan WinXP).</p>
<p>Cari Path di bahagian System Variables. Kemudian tambah C:/xampp/php/ pada hujung kandungan yang sedia ada. Pastikan anda memisahkan setiap path dengan ; . Ini contoh Path saya (&#8230;&#8230;&#8230; mewakili path-path lain yang sedia ada).</p>

<div class="wp_codebox"><table><tr id="p3617"><td class="code" id="p361code7"><pre class="dos" style="font-family:monospace;"><span style="color: #33cc33;">%</span><span style="color: #448888;">SystemRoot</span><span style="color: #33cc33;">%</span>\system32;<span style="color: #33cc33;">%</span><span style="color: #448888;">SystemRoot</span><span style="color: #33cc33;">%</span>;.........;C:\xampp\php\</pre></td></tr></table></div>

<p><a href="http://www.tutorialmelayu.com/wp-content/uploads/2010/12/Untitled.png"><img src="http://www.tutorialmelayu.com/wp-content/uploads/2010/12/Untitled.png" alt="" title="path" width="555" height="604" class="aligncenter size-full wp-image-371" /></a></p>
<p>Tekan Apply atau OK. Restart PC anda.</p>
<p>Buka command prompt anda dan taip php -v. Anda sepatutnya mendapat output seperti di bawah:</p>

<div class="wp_codebox"><table><tr id="p3618"><td class="code" id="p361code8"><pre class="dos" style="font-family:monospace;">C:\Users\mdpai&gt;php -v
PHP 5.3.1 <span style="color: #66cc66;">&#40;</span>cli<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>built: Nov <span style="color: #cc66cc;">20</span> <span style="color: #cc66cc;">2009</span> <span style="color: #cc66cc;">17</span>:<span style="color: #cc66cc;">26</span>:<span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span>
Copyright <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1997</span>-<span style="color: #cc66cc;">2009</span> The PHP Group
Zend Engine v2.3.0, Copyright <span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">1998</span>-<span style="color: #cc66cc;">2009</span> Zend Technologies</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/menggunakan-php-cli-di-dalam-windows/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP array</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/php-array</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/php-array#comments</comments>
		<pubDate>Fri, 03 Apr 2009 21:20:53 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[asas php]]></category>
		<category><![CDATA[belajar php mudah]]></category>
		<category><![CDATA[php array]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=120</guid>
		<description><![CDATA[Array adalah satu struktur yang boleh menyimpan satu atau lebih nilai. Anda boleh andaikan ia sebagai satu variable yang boleh menyimpan pelbagai nilai serentak. Ia sesuai digunakan jika anda ingin menyimpan beberapa nilai mengikut kumpulan yang sama. Untuk contoh, kita andaikan kita mahu menyimpan nama-nama pelajar di dalam array $pelajar. &#60;?php $pelajar&#91;0&#93; = &#34;abu&#34;; $pelajar&#91;1&#93; [...]]]></description>
			<content:encoded><![CDATA[<p>Array adalah satu struktur yang boleh menyimpan satu atau lebih nilai. Anda boleh andaikan ia sebagai satu variable yang boleh menyimpan pelbagai nilai serentak. Ia sesuai digunakan jika anda ingin menyimpan beberapa nilai mengikut kumpulan yang sama. Untuk contoh, kita andaikan kita mahu menyimpan nama-nama pelajar di dalam array $pelajar.</p>
<p><span id="more-120"></span></p>

<div class="wp_codebox"><table><tr id="p12012"><td class="code" id="p120code12"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">0</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;abu&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">1</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;bedah&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;kasim&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;husin&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;mdpai&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#91;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;mirul&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//output</span>
<span style="color: #dfc484;">print_r</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$pelajar</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Perhatikan bahawa nombor indeks sesuatu array bermula dari 0. Jadi, $pelajar[0] merujuk kepada nilai pertama array $pelajar, manakala $pelajar[3] merujuk kepada nilai ke empat array ini. Jika kita tidak memasukkan apa-apa nilai indeks ke dalam array tersebut, (seperti contoh terakhir di atas) secara automatik, nilai tersebut akan dimasukkan ke nombor indeks terakhir yang kosong. Dalam contoh ini, mdpai akan menjadi nilai ke lima array $pelajar manakala mirul nilai ke enam array $pelajar.</p>
<p>Setiap ahli array boleh dianggap sebagai variable yang berasingan. Lihat contoh di bawah yang menyimpan markah-markah seorang pelajar di dalam satu array dan kemudian mengira purata markah pelajar tersebut.</p>

<div class="wp_codebox"><table><tr id="p12013"><td class="code" id="p120code13"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">0</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">85</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">1</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">91</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">50</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$purata</span> <span style="color: #eeeeee;">=</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">0</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">1</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">/</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;purata markah <span style="color: #dfc484; font-weight: bold;">$purata</span> &quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Terdapat satu lagi jenis array yang sering digunakan iaitu associative array. Untuk array jenis ini, kita bagaikan memberikan nama untuk setiap ahli array tersebut. Lihat contoh di bawah untuk lebih memahami konsep associative array.</p>

<div class="wp_codebox"><table><tr id="p12014"><td class="code" id="p120code14"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;matematik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">85</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;fizik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">91</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;elektrik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">50</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$purata</span> <span style="color: #eeeeee;">=</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;matematik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;fizik&quot;</span><span style="color: #eeeeee;">&#93;</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$markah</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">&quot;elektrik&quot;</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">/</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;purata markah <span style="color: #dfc484; font-weight: bold;">$purata</span> &quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/php-array/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Query String</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/query-string</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/query-string#comments</comments>
		<pubDate>Wed, 01 Apr 2009 20:05:47 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[belajar php mudah]]></category>
		<category><![CDATA[melayu]]></category>
		<category><![CDATA[query string]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=116</guid>
		<description><![CDATA[Query string merupakan satu cara untuk kita menyimpan sesuatu nilai variable di dalam URL. Contohnya www.tutorialmelayu.com/index.php?variable1=nilai1. Dalam contoh ini, kita menyimpan nilai1 di dalam variable bernama variable1. Untuk menggunakan variable ini, kita hanya perlu menggunakan variable super global $_GET Contoh URL www.domain.com/pageA.php?nama=mdpai&#038;umur=23 pageA.php &#60;?php echo &#34;Hi $_GET['nama'], anda berumur $_GET['umur'] tahun ...&#34;; ?&#62; Output bagi [...]]]></description>
			<content:encoded><![CDATA[<p>Query string merupakan satu cara untuk kita menyimpan sesuatu nilai variable di dalam URL. Contohnya www.tutorialmelayu.com/index.php?variable1=nilai1. Dalam contoh ini, kita menyimpan nilai1 di dalam variable bernama variable1. Untuk menggunakan variable ini, kita hanya perlu menggunakan variable super global $_GET</p>
<p><span id="more-116"></span></p>
<p>Contoh URL<br />
www.domain.com/pageA.php?nama=mdpai&#038;umur=23</p>
<p>pageA.php</p>

<div class="wp_codebox"><table><tr id="p11617"><td class="code" id="p116code17"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Hi <span style="color: #dfc484; font-weight: bold;">$_GET</span>['nama'], anda berumur <span style="color: #dfc484; font-weight: bold;">$_GET</span>['umur'] tahun ...&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Output bagi kod di atas : <strong>Hi mdpai, anda berumur 23 tahun &#8230;</strong><br />
Untuk menggunakan query string ini, pastikan anda mengikut syntaxnya yang betul</p>
<p>www.domain.com/pageA.php<strong>?</strong>nama<strong>=</strong>mdpai<strong>&#038;</strong>umur<strong>=</strong>23</p>
<ul>
<li>Perhatikan saya meletakkan tanda ? selepas nama page.</li>
<li>Variable-variable dipisahkan oleh tanda &#038;</li>
</ul>
<p>Salah satu contoh biasa penggunaan query string adalah untuk membuat <em>include </em>page-page PHP yang berlainan. Lihat contoh berikut.</p>

<div class="wp_codebox"><table><tr id="p11618"><td class="code" id="p116code18"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #e8ed97;">switch</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$_GET</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">'page'</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&#123;</span>
<span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">'hello'</span><span style="color: #eeeeee;">:</span>
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">'hello.php'</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">'about'</span><span style="color: #eeeeee;">:</span>
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">'about.php'</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">'links'</span><span style="color: #eeeeee;">:</span>
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">'links.php'</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">default</span><span style="color: #eeeeee;">:</span>
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">'main.php'</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Jika anda menghadapi masalah dengan switch dan include, rujuk <a href="http://www.tutorialmelayu.com/web-programming/guna-switch-menggantikan-if-else">tutorial </a>ini dan <a href="http://www.tutorialmelayu.com/web-programming/memasukkan-external-file-menggunakan-include-require">tutorial </a>ini.<br />
Bergantung kepada nilai $_GET['page'], code PHP di atas akan membuat include page PHP tertentu.</p>
<p>Sebagai contoh, www.domain.com/pageB.php?page=about  akan memasukkan about.php ke dalam pageB.php anda.<br />
Contoh lain, www.domain.com/pageB.php?page=apaapajela akan memasukkan main.php ke dalam pageB.php anda memandangkan apaapajela.php tidak dinyatakan di dalam penyata switch anda.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/query-string/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>menulis function php sendiri</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri#comments</comments>
		<pubDate>Sun, 29 Mar 2009 13:02:09 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[belajar php melayu mudah]]></category>
		<category><![CDATA[function dalam php]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=104</guid>
		<description><![CDATA[Jika anda masih baru dengan function php, mungkin anda perlu merujuk tutorial ini dahulu. Untuk menambahkan fungsi dan menjadikan function itu lebih dinamik, kita boleh menambah parameter pada function kita. Function NamaSaya() di bawah memberi output yang berbeza untuk input yang berbeza. &#60;?php //function function UcapSelamat&#40;$nama&#41; &#123; echo &#34;Selamat Datang ke Tutorial Melayu, $nama! &#60;br&#62;&#34;; [...]]]></description>
			<content:encoded><![CDATA[<p>Jika anda masih baru dengan function php, mungkin anda perlu merujuk <a href="http://www.tutorialmelayu.com/web-programming/menulis-function-php-sendiri-asas">tutorial</a> ini dahulu.</p>
<p><span id="more-104"></span></p>
<p>Untuk menambahkan fungsi dan menjadikan function itu lebih dinamik, kita boleh menambah parameter pada function kita.</p>
<p>Function NamaSaya() di bawah memberi output yang berbeza untuk input yang berbeza.</p>

<div class="wp_codebox"><table><tr id="p10421"><td class="code" id="p104code21"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//function</span>
<span style="color: #dfc484; font-weight: bold;">function</span> UcapSelamat<span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$nama</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&#123;</span>
    <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Selamat Datang ke Tutorial Melayu, <span style="color: #dfc484; font-weight: bold;">$nama</span>! &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan</span>
UcapSelamat<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;mdpai&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
UcapSelamat<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;wan mohd fairuz&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh function lain</span>
<span style="color: #dfc484; font-weight: bold;">function</span> Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span><span style="color: #eeeeee;">,</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>
   <span style="color: #dfc484;">$c</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Hasil tambah <span style="color: #dfc484; font-weight: bold;">$a</span> dan <span style="color: #dfc484; font-weight: bold;">$b</span> ialah <span style="color: #dfc484; font-weight: bold;">$c</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan </span>
Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">,</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">5</span><span style="color: #eeeeee;">,</span> <span style="color: #ff8400;">2</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Dengan menggunakan function, kita bukan hanya boleh memproses nilai yang terdapat di parameter tetapi kita juga boleh memulangkan nilai tersebut untuk digunakan dalam code seterusnya. Lihat contoh:</p>

<div class="wp_codebox"><table><tr id="p10422"><td class="code" id="p104code22"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//contoh functio</span>
<span style="color: #dfc484; font-weight: bold;">function</span> Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span><span style="color: #eeeeee;">,</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>
   <span style="color: #dfc484;">$c</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
   <span style="color: #e8ed97;">return</span> <span style="color: #dfc484;">$c</span>
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan </span>
<span style="color: #dfc484;">$hasil</span> <span style="color: #eeeeee;">=</span> Tambah<span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">2</span><span style="color: #eeeeee;">,</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$hasil</span> <span style="color: #eeeeee;">&gt;</span><span style="color: #ff8400;">10</span><span style="color: #eeeeee;">&#41;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Lebih dari 10 &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">else</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Kurang dari 10 &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Function merupakan satu alat yang amat berkuasa di dalam PHP. Ianya digunakan dengan meluas di dalam komuniti PHP. Jadi pastikan anda betul-betul faham contoh yang diberikan.</p>
<p>Selamat mencuba!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Menulis function php sendiri &#8211; asas</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri-asas</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri-asas#comments</comments>
		<pubDate>Sun, 29 Mar 2009 11:53:01 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=102</guid>
		<description><![CDATA[Ok, kepada yang pernah balajar C atau C++ mungkin tahu bahawa function amat berguna di dalam dunia atur cara. Ia membenarkan kita menggunakan kembali sesuatu blok script bila-bila masa kita perlukan tanpa perlu menulis balik script tersebut. Langkah yang perlu diingati semasa membina function PHP: bermula dengan “function” namakan function anda “{” pada permulaan function [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, kepada yang pernah balajar C atau C++ mungkin tahu bahawa function amat berguna di dalam dunia atur cara. Ia membenarkan kita menggunakan kembali sesuatu blok script bila-bila masa kita perlukan tanpa perlu menulis balik script tersebut.</p>
<p><span id="more-102"></span></p>
<p>Langkah yang perlu diingati semasa membina function PHP:</p>
<ul>
<li>bermula dengan “function”</li>
<li>namakan function anda</li>
<li>“{” pada permulaan function anda</li>
<li>kod-kod anda</li>
<li>akhiri dengan “}”</li>
</ul>
<p>Sebagai contoh pertama, kita akan menulis function NamaSaya() yang akan memaparkan nama apabila dipanggil:</p>

<div class="wp_codebox"><table><tr id="p10224"><td class="code" id="p102code24"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//function</span>
<span style="color: #dfc484; font-weight: bold;">function</span> NamaSaya<span style="color: #eeeeee;">&#40;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&#123;</span>
    <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Wan Mohd Fairuz&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//contoh penggunaan</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Selamat Datang &quot;</span><span style="color: #eeeeee;">;</span>
NamaSaya<span style="color: #eeeeee;">&#40;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Nama anda &quot;</span><span style="color: #eeeeee;">;</span>
NamaSaya<span style="color: #eeeeee;">&#40;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Anda boleh perhatikan yang saya telah menggunakan dua kali function NamaSaya dalam code di atas tanpa perlu menaip dua kali code yang sama. Tutorial function yang akan datang akan menerangkan dengan lebih lanjut penggunaan function yang lebih advance.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/menulis-function-php-sendiri-asas/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>html form</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/html-form</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/html-form#comments</comments>
		<pubDate>Sun, 29 Mar 2009 01:03:37 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[html & css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[belajar php senang mudah]]></category>
		<category><![CDATA[html form]]></category>
		<category><![CDATA[php asas]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=98</guid>
		<description><![CDATA[HTML form digunakan untuk mengumpul maklumat dari pengguna (users) dan menghantar maklumat ini ke server untuk diproses. Untuk tutorial ini, saya akan menunjukkan contoh ringkas di mana pengguna akan memasukkan nama dan e-mail mereka, dan kita akan memaparkan maklumat ini kembali kepada pengguna tersebut. Contoh form.html &#60;html&#62;&#60;body&#62; &#60;h4&#62;Tutorial Melayu E- Commerce&#60;/h4&#62; &#60;form action=&#34;proses.php&#34; method=&#34;post&#34;&#62; Nama: [...]]]></description>
			<content:encoded><![CDATA[<p>HTML form digunakan untuk mengumpul maklumat dari pengguna (users) dan menghantar maklumat ini ke server untuk diproses. Untuk tutorial ini, saya akan menunjukkan contoh ringkas di mana pengguna akan memasukkan nama dan e-mail mereka, dan kita akan memaparkan maklumat ini kembali kepada pengguna tersebut.</p>
<p><span id="more-98"></span></p>
<p>Contoh form.html</p>

<div class="wp_codebox"><table><tr id="p9827"><td class="code" id="p98code27"><pre class="html" style="font-family:monospace;">&lt;html&gt;&lt;body&gt;
&lt;h4&gt;Tutorial Melayu E- Commerce&lt;/h4&gt;
&lt;form action=&quot;proses.php&quot; method=&quot;post&quot;&gt; 
Nama: &lt;input type=&quot;text&quot; name=&quot;nama&quot;/&gt;&lt;br&gt;
Email: &lt;input type=&quot;text&quot; name=&quot;email&quot;/&gt; 
&lt;input type=&quot;submit&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;&lt;/html&gt;</pre></td></tr></table></div>

<p>Jika anda perhatikan, saya meletakkan attribute action=&#8221;proses.php&#8221; di dalam  tag form html di atas. Ia membawa maksud, jika pengguna menekan butang submit, hantar semua maklumat dari html form ke page proses.php. Jadi secara ringkasnya</p>
<p>Contoh proses.php</p>

<div class="wp_codebox"><table><tr id="p9828"><td class="code" id="p98code28"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$nama</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$_POST</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">'nama'</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$email</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$_POST</span><span style="color: #eeeeee;">&#91;</span><span style="color: #ff8400;">'email'</span><span style="color: #eeeeee;">&#93;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$masa</span> <span style="color: #eeeeee;">=</span> <span style="color: #e8ed97;">echo</span> <span style="color: #dfc484;">date</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">'l jS \of F Y h:i:s A'</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Selamat Datang <span style="color: #dfc484; font-weight: bold;">$nama</span>. &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Email anda ialah <span style="color: #dfc484; font-weight: bold;">$email</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;Masa : <span style="color: #dfc484; font-weight: bold;">$masa</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p> Semua maklumat dari html form boleh diperolehi dari variable $_POST. Jika anda perhatikan, di dalam form.html, saya telah setkan name=&#8221;nama&#8221; dan name=&#8221;email&#8221; : nama-nama inilah yang akan kita gunakan untuk mengenal pasti maklumat mana yang mahu kita proses. Dalam tutorial ringkas ini, saya hanya menggunakan maklumat yang saya perolehi dari user untuk dipaparkan semula ke dalam browser.</p>
<p>Kita boleh bayangkan yang, kita boleh membuat perkiraan, perubahan, sambungan ke pangkalan data, atau apa saja dengan menggunakan maklumat yang diperolehi dari html form ini. Untuk memastikan anda boleh mengatur cara php dengan baik, pastikan anda betul-betul faham dengan bagaimana html form berfungsi.</p>
<p>Selamat mencuba!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/html-form/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Guna switch menggantikan if else</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/guna-switch-menggantikan-if-else</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/guna-switch-menggantikan-if-else#comments</comments>
		<pubDate>Sat, 28 Mar 2009 23:50:49 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[php asas]]></category>
		<category><![CDATA[switch ganti if else]]></category>
		<category><![CDATA[tutorial php mudah]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=94</guid>
		<description><![CDATA[Sekiranya anda mempunyai struktur if else yang kompleks seperti berikut, anda boleh menggantikannya dengan struktur switch yang jauh lebih mudah untuk difahami. &#60;?php $destinasi = &#34;kota bharu&#34;; &#160; if&#40;$destinasi == &#34;kuala lumpur&#34;&#41; echo &#34;mahu pergi kuala lumpur &#60;br&#62;&#34;; else if&#40;$destinasi == &#34;johor bahru&#34;&#41; echo &#34;mahu pergi johor bahru &#60;br&#62;&#34;; else if&#40;$destinasi == &#34;kota bharu&#34;&#41; echo [...]]]></description>
			<content:encoded><![CDATA[<p>Sekiranya anda mempunyai struktur if else yang kompleks seperti berikut, anda boleh menggantikannya dengan struktur switch yang jauh lebih mudah untuk difahami.</p>
<p><span id="more-94"></span></p>

<div class="wp_codebox"><table><tr id="p9431"><td class="code" id="p94code31"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$destinasi</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;kota bharu&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$destinasi</span> <span style="color: #eeeeee;">==</span> <span style="color: #ff8400;">&quot;kuala lumpur&quot;</span><span style="color: #eeeeee;">&#41;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi kuala lumpur &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">else</span> <span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$destinasi</span> <span style="color: #eeeeee;">==</span> <span style="color: #ff8400;">&quot;johor bahru&quot;</span><span style="color: #eeeeee;">&#41;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi johor bahru &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">else</span> <span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$destinasi</span> <span style="color: #eeeeee;">==</span> <span style="color: #ff8400;">&quot;kota bharu&quot;</span><span style="color: #eeeeee;">&#41;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi kota bharu &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">else</span> <span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$destinasi</span> <span style="color: #eeeeee;">==</span> <span style="color: #ff8400;">&quot;kuantan&quot;</span><span style="color: #eeeeee;">&#41;</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi kuantan &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">else</span>
   <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;tak pegi mana mana&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Boleh digantikan dengan</p>

<div class="wp_codebox"><table><tr id="p9432"><td class="code" id="p94code32"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$destinasi</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;kota bharu&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">switch</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$destinasi</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>
    <span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">&quot;kuala lumpur&quot;</span> <span style="color: #eeeeee;">:</span> 
        <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi kuala lumpur&quot;</span><span style="color: #eeeeee;">;</span> 
    <span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
    <span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">&quot;johor bahru&quot;</span> <span style="color: #eeeeee;">:</span> 
        <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi johor bahru&quot;</span><span style="color: #eeeeee;">;</span> 
    <span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
    <span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">&quot;kota bharu&quot;</span> <span style="color: #eeeeee;">:</span> 
        <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi kota bharu&quot;</span><span style="color: #eeeeee;">;</span> 
    <span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
    <span style="color: #e8ed97;">case</span> <span style="color: #ff8400;">&quot;kuantan&quot;</span> <span style="color: #eeeeee;">:</span> 
        <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;mahu pergi kuantan&quot;</span><span style="color: #eeeeee;">;</span> 
    <span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
    <span style="color: #e8ed97;">default</span> <span style="color: #eeeeee;">:</span>
        <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;tak pegi mana mana&quot;</span><span style="color: #eeeeee;">;</span> 
    <span style="color: #e8ed97;">break</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Jika anda perhatikan setiap case diakhiri dengan break; . Ianya untuk mengelakkan case yang seterusnya diexecute. Pastikan juga anda meletakkan case default, case ini akan diexecute jika struktur switch tidak menjumpai case yang sama dengan nilai $destinasi. Walaupun tidak wajib, namun saya sarankan anda memasukkan default setiap kali anda menggunakan switch.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/guna-switch-menggantikan-if-else/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>membuat kiraan dalam php menggunakan operators aritmetik &amp; logik</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/membuat-kiraan-dalam-php-menggunakan-operators-aritmetik-logik</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/membuat-kiraan-dalam-php-menggunakan-operators-aritmetik-logik#comments</comments>
		<pubDate>Sat, 28 Mar 2009 20:21:35 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[kiraan dalam php]]></category>
		<category><![CDATA[logik php]]></category>
		<category><![CDATA[matematik php]]></category>
		<category><![CDATA[php asas]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=79</guid>
		<description><![CDATA[Untuk melakukan pengiraan aritmetik, seperti 2 + 2 atau 17 * 5, kita boleh menggunakan operator berikut; &#60;?php // dua operand a dan b $a = 8; $b = 4; &#160; //tambah $c = $a + $b; echo &#34;hasil tambah $c &#60;br&#62;&#34;; &#160; //tolak $d = $a - $b; echo &#34;hasil tolak $d &#60;br&#62;&#34;; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Untuk melakukan pengiraan aritmetik, seperti 2 + 2 atau 17 * 5, kita boleh menggunakan operator berikut;</p>
<p><span id="more-79"></span></p>

<div class="wp_codebox"><table><tr id="p7936"><td class="code" id="p79code36"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// dua operand a dan b</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">8</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">4</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//tambah</span>
<span style="color: #dfc484;">$c</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil tambah <span style="color: #dfc484; font-weight: bold;">$c</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//tolak</span>
<span style="color: #dfc484;">$d</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">-</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil tolak <span style="color: #dfc484; font-weight: bold;">$d</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//darab</span>
<span style="color: #dfc484;">$e</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">*</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil darab <span style="color: #dfc484; font-weight: bold;">$e</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//bahagi</span>
<span style="color: #dfc484;">$f</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">/</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil bahagi <span style="color: #dfc484; font-weight: bold;">$f</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//mencari baki hasil dari bahagi</span>
<span style="color: #dfc484;">$g</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">%</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;hasil baki <span style="color: #dfc484; font-weight: bold;">$g</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Terdapat beberapa short form atau singkatan untuk beberapa operasi matematik yang sering digunakan di dalam PHP seperti ++ dan &#8211;.</p>

<div class="wp_codebox"><table><tr id="p7937"><td class="code" id="p79code37"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #ff8400;">1</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span><span style="color: #eeeeee;">++;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">-</span> <span style="color: #ff8400;">1</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span><span style="color: #eeeeee;">--;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">*</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">*=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">/</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">/=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cara biasa</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//boleh digantikan dengan </span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">+=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;nilai -&gt; <span style="color: #dfc484; font-weight: bold;">$a</span> &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Manakala operator logik pula digunakan untuk membuat test terhadap sesuatu nilai variable. Ianya selalunya digunakan dengan if else.</p>

<div class="wp_codebox"><table><tr id="p7938"><td class="code" id="p79code38"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">10</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">6</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a sama nilai dengan $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">==</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a tak sama nilai dengan $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">!=</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a lagi besar dari $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">&gt;</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a lagi kecil dari $b</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">&lt;</span> <span style="color: #dfc484;">$b</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a sama dengan 10 DAN $b sama dengan 6</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">10</span> <span style="color: #eeeeee;">&amp;&amp;</span> <span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">6</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// maksud : kalau $a sama dengan 10 ATAU $b sama dengan 3</span>
<span style="color: #e8ed97;">if</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$a</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">10</span> <span style="color: #eeeeee;">||</span> <span style="color: #dfc484;">$b</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">3</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">&#123;</span>  
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;true &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span> 
<span style="color: #e8ed97;">else</span> 
  <span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;false &lt;br&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/membuat-kiraan-dalam-php-menggunakan-operators-aritmetik-logik/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memasukkan external file menggunakan include / require</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/memasukkan-external-file-menggunakan-include-require</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/memasukkan-external-file-menggunakan-include-require#comments</comments>
		<pubDate>Thu, 26 Mar 2009 18:44:58 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=81</guid>
		<description><![CDATA[Function include atau require digunakan untuk memasukkan code-code dari fail lain ke dalam page php anda. header.php &#60;?php //file header.php ?&#62; &#60;html&#62; &#60;head&#62;&#60;/head&#62; &#60;body&#62; &#60;p&#62;Ini Header&#60;/p&#62; footer.php &#60;?php //file footer.php echo &#34;&#60;p&#62;Ini footer.php&#60;/p&#62;&#34;; ?&#62; &#60;/body&#62; &#60;/html&#62; index.php &#60;?php //file index.php include&#40;&#34;header.php&#34;&#41;; &#160; echo &#34;&#60;p&#62;Hello World.&#60;/p&#62;&#34;; &#160; include&#40;&#34;footer.php&#34;&#41;; ?&#62; Penggunaan include tidak terhad kepada ni saja, [...]]]></description>
			<content:encoded><![CDATA[<p>Function include atau require digunakan untuk memasukkan code-code dari fail lain ke dalam page php anda.</p>
<p>header.php</p>

<div class="wp_codebox"><table><tr id="p8144"><td class="code" id="p81code44"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//file header.php</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span>
<span style="color: #eeeeee;">&lt;</span>html<span style="color: #eeeeee;">&gt;</span>
<span style="color: #eeeeee;">&lt;</span>head<span style="color: #eeeeee;">&gt;&lt;/</span>head<span style="color: #eeeeee;">&gt;</span>
<span style="color: #eeeeee;">&lt;</span>body<span style="color: #eeeeee;">&gt;</span>
<span style="color: #eeeeee;">&lt;</span>p<span style="color: #eeeeee;">&gt;</span>Ini Header<span style="color: #eeeeee;">&lt;/</span>p<span style="color: #eeeeee;">&gt;</span></pre></td></tr></table></div>

<p><span id="more-81"></span></p>
<p>footer.php</p>

<div class="wp_codebox"><table><tr id="p8145"><td class="code" id="p81code45"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//file footer.php</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;&lt;p&gt;Ini footer.php&lt;/p&gt;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span>
<span style="color: #eeeeee;">&lt;/</span>body<span style="color: #eeeeee;">&gt;</span>
<span style="color: #eeeeee;">&lt;/</span>html<span style="color: #eeeeee;">&gt;</span></pre></td></tr></table></div>

<p>index.php</p>

<div class="wp_codebox"><table><tr id="p8146"><td class="code" id="p81code46"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//file index.php</span>
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;header.php&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">&quot;&lt;p&gt;Hello World.&lt;/p&gt;&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;footer.php&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Penggunaan include tidak terhad kepada ni saja, anda boleh membayangkan anda mempunyai fail connection.php yang mempunyai maklumat tentang sambungan ke pangkalan data (database) anda dan anda boleh memasukkan file ini kepada semua page anda yang memerlukan sambungan ke pangkalan data.</p>
<p>connection.php</p>

<div class="wp_codebox"><table><tr id="p8147"><td class="code" id="p81code47"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$server</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;localhost&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$username</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;root&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$password</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;&quot;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$database</span> <span style="color: #eeeeee;">=</span> <span style="color: #ff8400;">&quot;tutorialmelayu&quot;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #dfc484;">$link</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">mysql_connect</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$server</span><span style="color: #eeeeee;">,</span> <span style="color: #dfc484;">$username</span><span style="color: #eeeeee;">,</span> <span style="color: #dfc484;">$password</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">mysql_select_db</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$database</span><span style="color: #eeeeee;">,</span> <span style="color: #dfc484;">$link</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Jadi setiap kali anda memerlukan penggunaan database, anda hanya perlu memasukkan connection.php ke dalam page anda. Tidak perlu lagi menulis code yang sama berulang-ulang kali.</p>
<p>pageA.php</p>

<div class="wp_codebox"><table><tr id="p8148"><td class="code" id="p81code48"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #e8ed97;">include</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;connection.php&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//masukkan apa2 code di bawah</span>
<span style="color: #dfc484;">$result</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">mysql_query</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;SELECT * FROM table&quot;</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
<span style="color: #dfc484;">$row</span> <span style="color: #eeeeee;">=</span> <span style="color: #dfc484;">mysql_fetch_assoc</span><span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">$result</span><span style="color: #eeeeee;">&#41;</span><span style="color: #eeeeee;">;</span>
&nbsp;
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Selamat mencuba!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/memasukkan-external-file-menggunakan-include-require/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>if else &amp; ternary conditionals</title>
		<link>http://www.tutorialmelayu.com/web-programming/php/if-else-ternary-conditionals</link>
		<comments>http://www.tutorialmelayu.com/web-programming/php/if-else-ternary-conditionals#comments</comments>
		<pubDate>Sun, 08 Feb 2009 09:00:20 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[belajar php melayu]]></category>
		<category><![CDATA[if else]]></category>
		<category><![CDATA[ternary operator]]></category>

		<guid isPermaLink="false">http://www.tutorialmelayu.com/?p=58</guid>
		<description><![CDATA[Kod di bawah bermaksud, jika condition true, buat statement1, jika false buat statement2. if &#40;condition&#41; &#123; statement1; &#125; else &#123; statement2; &#125; Mari kita lihat contoh sebenar di dalam PHP; &#60;?php if &#40;date&#40;&#34;G&#34;&#41; &#60; 12&#41; &#123; echo 'Selamat Pagi'; &#125; else &#123; echo 'Selamat Petang'; &#125; ?&#62; Namun, statement if else ini boleh disingkatkan lagi [...]]]></description>
			<content:encoded><![CDATA[<p>Kod di bawah bermaksud, jika condition true, buat statement1, jika false buat statement2. </p>
<p><span id="more-58"></span></p>

<div class="wp_codebox"><table><tr id="p5853"><td class="code" id="p58code53"><pre class="php" style="font-family:monospace;"><span style="color: #e8ed97;">if</span> <span style="color: #eeeeee;">&#40;</span>condition<span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&#123;</span>
   statement1<span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span> <span style="color: #e8ed97;">else</span> <span style="color: #eeeeee;">&#123;</span>
   statement2<span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span></pre></td></tr></table></div>

<p>Mari kita lihat contoh sebenar di dalam PHP;</p>

<div class="wp_codebox"><table><tr id="p5854"><td class="code" id="p58code54"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #e8ed97;">if</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">date</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;G&quot;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&lt;</span> <span style="color: #ff8400;">12</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&#123;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">'Selamat Pagi'</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span> <span style="color: #e8ed97;">else</span> <span style="color: #eeeeee;">&#123;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #ff8400;">'Selamat Petang'</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee;">&#125;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Namun, statement if else ini boleh disingkatkan lagi dengan menggunakan operator ternary. Ternary Conditionals (menggunakan operator ternary) adalah salah satu cara untuk menjimatkan masa anda menulis code PHP. Strukturnya yang kelihatan <del datetime="2009-02-08T05:19:14+00:00">susah</del> pelik untuk difahami menyebabkan ianya tidak popular dikalangan programmer.<br />
Contoh di atas boleh ditulis semula dengan;</p>

<div class="wp_codebox"><table><tr id="p5855"><td class="code" id="p58code55"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">date</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;G&quot;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&lt;</span> <span style="color: #ff8400;">12</span><span style="color: #eeeeee;">&#41;</span> ? <span style="color: #ff8400;">'Selamat Pagi'</span> <span style="color: #eeeeee;">:</span> <span style="color: #ff8400;">'Selamat Petang'</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>atau</p>

<div class="wp_codebox"><table><tr id="p5856"><td class="code" id="p58code56"><pre class="php" style="font-family:monospace;"><span style="color: #dfc484; font-weight: bold;">&lt;?php</span>
<span style="color: #dfc484;">$greeting</span> <span style="color: #eeeeee;">=</span> <span style="color: #eeeeee;">&#40;</span><span style="color: #dfc484;">date</span><span style="color: #eeeeee;">&#40;</span><span style="color: #ff8400;">&quot;G&quot;</span><span style="color: #eeeeee;">&#41;</span> <span style="color: #eeeeee;">&lt;</span> <span style="color: #ff8400;">12</span><span style="color: #eeeeee;">&#41;</span> ? <span style="color: #ff8400;">'Selamat Pagi'</span> <span style="color: #eeeeee;">:</span> <span style="color: #ff8400;">'Selamat Petang'</span><span style="color: #eeeeee;">;</span>
<span style="color: #e8ed97;">echo</span> <span style="color: #dfc484;">$greeting</span><span style="color: #eeeeee;">;</span>
<span style="color: #eeeeee; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><a href="http://www.tutorialmelayu.com/wp-content/uploads/2009/02/800px-php-n_logosvg2.png"><img src="http://www.tutorialmelayu.com/wp-content/uploads/2009/02/800px-php-n_logosvg2.png" alt="800px-php-n_logosvg2" title="800px-php-n_logosvg2" width="256" height="134" class="alignnone size-full wp-image-74" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tutorialmelayu.com/web-programming/php/if-else-ternary-conditionals/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

