01010111010101011011000110101010101010110101010111010101011010101010101010101010101010101010101010101010
01010111010101011011000110101010101010110101010111010101011010101010101010101010101010101010101010101010
01010111010101011011000110101010101010110101010111010101011010101010101010101010101010101010101010101010
01010111010101011011000110101010101010110101010111010101011010101010101010101010101010101010101010101010
01010111010101011011000110101010101010110101010111010101011010101010101010101010101010101010101010101010
01010111010101011011000110101010101010110101010111010101011010101010101010101010101010101010101010101010

Metode Searching Sederhana PHP

Buat database !
create database cms_db;
use cms_db;
create table cms_artikel (id int(3) primary key auto_increment,
              judul_artikel varchar(100), penulis_artikel varchar(70),
              isi_artikel text);
insert into cms_artikel values(”,’judul1’,'P1’,'Belajar PHP itu mudah’);
insert into cms_artikel values(”,’judul2’,'P2’,'Belajar menyenangkan jika yang diperajari kesukaannya‘);

Buat file koneksi.php
// koneksi.php
<?php
$host = “localhost”;
$username = “root”;
$password = “”;
$databasename = “cms_db”;
$connect = mysql_connect($host, $username, $password) or die (“Nggak bisa konek !”);
mysql_select_db($databasename, $connect) or die(“Nggak bisa konek !”);
?>

Buat file index.php
// index.php :
<?php
include “config.php”;
$mode = $_REQUEST['mode'] ;
$id = $_REQUEST['id'];
$search = trim($_POST['search']); // menghilangkan space di kiri dan kanannya
$searchquery = “select * from cms_artikel where isi_artikel like ‘%$search%’”;
$runsearchquery = mysql_query($searchquery);
$viewquery = “select * from cms_artikel where id = ‘$id’”;
$runviewquery = mysql_query($viewquery);
if ($mode == “search” )
{
$numrows = mysql_num_rows($runsearchquery);
print “<br>Data yang anda cari, ada dalam database sebanyak : $numrows<hr>” ;
    while ( $result = mysql_fetch_array($runsearchquery))
    {
    $id = $result['id'];
    $judul = $result['judul_artikel'] ;
  
    print “<a href=?mode=view&id=$id>$judul</a><br>”;
}
print “<hr><a href=index.php>kembali</a>”;
}
else if($mode == “view”)
{
    while ( $result = mysql_fetch_array($runviewquery))
    {
    $id = $result['id'];
    $judul = $result['judul_artikel'] ;
    $penulis = $result['penulis_artikel'];
    $isi = $result['isi_artikel'];
    print “$judul<br>$penulis<br>$isi”;
    }
print “<hr><a href=index.php>kembali</a>”;
}
else{
?>
<html>
<head>
<title>Search Database … </title></head>
<body>
<br>
<table border=1 align=left bgcolor=lightblue>
<form method=POST action=?mode=search>
<tr><td>Search:<br><input type=text name=search> <input type=submit name=submit value=Cari></td></tr>
</form>
</body>
</html>
<?php
}
?>
Share this article :
 
 
Support : Creating Website | Mohammad Mastur
Copyright © 2011. Catatan Harianku - All Rights Reserved
Template Created by Creating Website Published by Mohammad Mastur
Proudly powered by Blogger