Konektivitas PHP - MySQL

1 / 102
About This Presentation
Title:

Konektivitas PHP - MySQL

Description:

... FormNilai.php while ($data = mysql_fetch_array($hasil)) { echo – PowerPoint PPT presentation

Number of Views:2
Avg rating:3.0/5.0
Slides: 103
Provided by: upi8

less

Transcript and Presenter's Notes

Title: Konektivitas PHP - MySQL


1
Konektivitas PHP - MySQL PHP - 2 Ir. H.
Sumijan, M.Sc
2
Koneksi PHP - MySQL
  • Untuk melakukan koneksi PHP dengan MySQL
    digunakan perintah mysql_connect() -gt skrip PHP.
  • Syntak mysql_connect(hostname,username,passw
    ord)

3
Koneksi PHP - MySQL
  • Setelah terkoneksi, pilihlah database.
  • Bila database yang diinginkan belum tersedia,
    buatlah databasenya.
  • Buatlah tabel, dengan struktur datanya.

4
Koneksi PHP - MySQL
lt? //Membuat database MySQL nama_db
dbbola" buat_db "create database
nama_db" sambung mysql_connect("localhost","
root","") if(sambung) echo "Koneksi
Berhasil" else echo "Koneksi Gagal" q_db
mysql_query(buat_db) if(q_db) echo "ltbrgt
Database nama_db berhasil dibuat" else echo
"ltbrgt Database nama_db gagal dibuat" ?gt
Koneksi Database
5
Koneksi PHP - MySQL
lt? //Membuat tabel MySQL nama_db
dbbola" nama_tbl "Liga" sambung
mysql_connect("localhost","root","") if(sambung)
echo "Koneksi Berhasil" else echo
"Koneksi Gagal" mysql_select_db(nama_db,sambu
ng) or die("Koneksi ke nama_db
gagal") buat_tbl "create table nama_tbl
(kode char(5) not null, negara char(10) not null,
champion int)" qtbl mysql_query(buat_tbl,sa
mbung) if(qtbl) echo "ltbrgtTabelnama_tbl
berhasil dibuat" else echo "ltbrgtTabel
nama_tbl gagal dibuat" ?gt
Membuat Tabel
6
Koneksi PHP - MySQL
  • Membuat Form sebagai input pada sistem database.
  • Input disimpan dalam satu tabel tertentu.
  • Pada attribut action ditentukan file yang
    memiliki skrip PHP untuk menyimpan input ke tabel
    pada database.

7
Koneksi PHP - MySQL
lthtmlgt ltheadgt lttitlegtFormulir Input
Ligalt/titlegt ltmeta authorSoegt lt/headgt ltbodygt lth1
gtMasukkan Data Ligalt/h1gt ltform methodpost
actionsimpan.phpgt lttablegt lttrgt
lttdgtKodelt/tdgt lttdgtltinput typetext namekode
size20gtlt/tdgt lt/trgt lttrgt lttdgtNegaralt/tdgt
lttdgtltinput typetext namenegara size20gtlt/tdgt
lt/trgt
Skrip Form Input
8
Koneksi PHP - MySQL
lttrgt lttdgtChampionlt/tdgt lttdgtltinput typetext
namechampion size20gtlt/tdgt lt/trgt lttrgt lttd
aligncentergtltinput typesubmit namesubmit
valueSimpangtlt/tdgt lttd aligncentergtltinput
typereset namereset valueUlangigtlt/tdgt lt/trgt
lt/tablegt lt/formgt lt/bodygt lt/htmlgt
9
Koneksi PHP - MySQL
10
Koneksi PHP - MySQL
  • Untuk menyimpan input ke tabel MySQL, terlebih
    dahulu input dibaca sesuai metode yang digunakan.
  • Untuk menyimpan ke database digunakan perintah
  • hasil mysql_query(SQL Statement)

11
Koneksi PHP - MySQL
lt? sambung mysql_connect("localhost","root","")
mysql_select_db(dbbola,sambung) or
die("Koneksi ke dbbola gagal") ?gt lthtmlgt ltheadgt
lttitlegtSimpan Ligalt/titlegt ltmeta
authorSoegt lt/headgt ltbodygt lth1gtData
Baranglt/h1gt lt? kode _POSTkode negara
_POSTnegara champion _POSTchampion ?gt
Skrip Simpan Data
12
Koneksi PHP - MySQL
lt? q_simpan "insert into Liga values('kode'
,'negara','champion')" hasil
mysql_query(q_simpan,sambung) if(hasil) echo
"Data tersimpan ltbrgt" echo "Kode
".kode."ltbrgt" echo "Negara
".negara."ltbrgt" echo "Champion
".champion."ltbrgt" else echo "Data gagal
disimpan" ?gt ltform methodpost
actionfrm_input_Liga.phpgt ltinput typesubmit
valueKembaligt lt/formgt lt/bodygt lt/htmlgt
Skrip Simpan Data
13
Koneksi PHP - MySQL
14
Koneksi PHP - MySQL
lt? tampil "select from Liga" q_buat
mysql_query(tampil,sambung) ?gt lttable
border1gt lttrgt lttdgtKodelt/tdgt lttdgtNegaralt/tdgt
lttdgtChampionlt/tdgt lt/trgt lt? while(row
mysql_fetch_row(q_buat)) echo ("lttr
aligncentergtlttdgtrow0lt/tdgt") echo
("lttdgtrow1lt/tdgt") echo ("lttdgtrow2lt/tdgtlt/trgt
") ?gt lt/tablegt lt? //ltform methodpost
actionedit.phpgtltinput typesubmit valueEdit
nameeditgtlt/formgt //ltform methodpost
actiontambah.phpgtltinput typesubmit valueTambah
nametambahgtlt/formgt ?gt
Skrip Menampilkan Data
15
Koneksi PHP - MySQL
16
Koneksi PHP - MySQL
  • Form Pencarian
  • Buat Input dengan type radio untuk memilih field
    pencarian.
  • Buat Input dengan type text sebagai kata kunci
    pencarian.
  • Buat tombol Cari, Input -gt type Submit

17
Koneksi PHP - MySQL
ltHTMLgt ltHEADgt lttitlegtCari Databaselt/titlegt lt/HE
ADgt ltBODYgt lth1gtSearching Liga untuk database
MySQLlt/h1gt ltform action"hasilsearch.php"
method"post"gt ltselect name"kolom"gt ltoption
value"kode"gtKodelt/optiongt ltoption
value"negara"gtNegaralt/optiongt lt/selectgt Masukkan
kata yang anda cari ltinput type "text" type
"text" name"cari"gt ltinput type "submit"
value"cari" gt lt/formgt lt/BODYgt lt/HTMLgt
Form - Search
18
Koneksi PHP - MySQL
19
Koneksi PHP - MySQL
lt? kolom_POST'kolom' cari_POST'cari'
connmysql_connect("localhost","root","")
mysql_select_db(dbbola", conn)
hasilmysql_query("select from Liga where
kolom like 'cari'", conn)
jumlahmysql_num_rows(hasil) echo "ltbrgt"
echo "Ditemukan jumlah" echo "ltbrgt"
while(barismysql_fetch_array(hasil))
echo "Kode " echo baris0 echo
"ltbrgt" echo "Negara " echo baris1
echo "ltbrgt" echo "Champion " echo
baris2 ?gt
Skrip Search
20
Koneksi PHP - MySQL
21
Contoh Kasus - 1
CREATE TABLE employee (id int(12) NOT NULL
auto_increment,name varchar(255) NOT
NULL,address varchar(255) NOT NULL,city
varchar(255) NOT NULL,PRIMARY KEY (id))
ENGINEMyISAM DEFAULT CHARSETlatin1
AUTO_INCREMENT7 INSERT INTO employee (id,
name, address, city) VALUES (1, 'Soe', '10
street dane', 'Pune'),(2, 'Debie', '12907A 53 St
NW', 'Mumbai'),(3, 'Atika', '3rd Floor, 888 Fort
Street', 'Noida'),(4, 'Widya', 'Sir Frederick W
Haultain Building 9811 109 ST NW', 'London'),(5,
'Danny', 'Suite 303, 13220 St. Albert Trail',
'Sydney'),(6, 'Yettri', '9700 Jasper Avenue',
'Perth')
Nama Database dbwork Script Table mahasiswa
22
Nama File Config.php
lt? sDbHost 'localhost' sDbName
dbwork' sDbUser 'root' sDbPwd
'' dbConn mysql_connect (sDbHost, sDbUser,
sDbPwd) or die ('MySQL connect failed. ' .
mysql_error()) mysql_select_db(sDbName,dbConn)
or die('Cannot select database. ' .
mysql_error()) ?gt
23
Nama File View.php
lthtmlgt ltheadgt lttitlegtView Recordslt/titlegt lt/headgt
ltlink href"style.css" rel"stylesheet"
type"text/css"gt ltbodygt lt?php include('config.php'
) result mysql_query("SELECT FROM
employee") or die(mysql_error()) echo "lttable
border'1' cellpadding'10'gt" echo
"lttrgt ltthgtltfont color'FFFF00'gtIdlt/fontgtlt/thgt ltth
gtltfont color'FFFF00'gtNamelt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtAddresslt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtCitylt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtEditlt/fontgtlt/thgt ltthgtltfont
color'FFFF00'gtDeletelt/fontgtlt/thgt lt/trgt"
24
Lanjutan Nama File View.php
while(row mysql_fetch_array( result )) echo
"lttrgt" echo 'lttdgtltbgtltfont color"663300"gt' .
row'id' . 'lt/fontgtlt/bgtlt/tdgt' echo
'lttdgtltbgtltfont color"663300"gt' . row'name' .
'lt/fontgtlt/bgtlt/tdgt' echo 'lttdgtltbgtltfont
color"663300"gt' . row'address' .
'lt/fontgtlt/bgtlt/tdgt' echo 'lttdgtltbgtltfont
color"663300"gt' . row'city' .
'lt/fontgtlt/bgtlt/tdgt' echo 'lttdgtltbgtltfont
color"663300"gtlta href"edit.php?id' .
row'id' . '"gtEditlt/agtlt/fontgtlt/bgtlt/tdgt' echo
'lttdgtltbgtltfont color"663300"gtlta
href"delete.php?id' . row'id' .
'"gtDeletelt/agtlt/fontgtlt/bgtlt/tdgt' echo
"lt/trgt" echo "lt/tablegt" ?gt ltpgtlta
href"insert.php"gtInsert new recordlt/agtlt/pgt lt/body
gt lt/htmlgt
25
Nama File Insert.php
lt?php function valid(name, address,city,
error) ?gt lthtmlgt ltheadgt lttitlegtInsert
Recordslt/titlegt lt/headgt ltlink href"style.css"
rel"stylesheet" type"text/css"gt ltbodygt lt?php if
(error ! '') echo 'ltdiv style"padding4px
border1px solid red colorred"gt'.error.'lt/divgt
' ?gt ltform action"" method"post"gt lttable
border"1"gt lttrgt lttd colspan"2"gtltbgtltfont
color'Red'gtInsert Records lt/fontgtlt/bgtlt/tdgt lt/trgt
26
Lanjutan Nama File Insert.php
lttrgt lttd width"179"gtltbgtltfont color'663300'gtName
ltemgtlt/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"name" value"lt?php echo name
?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtAddressltemgtlt
/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"address" value"lt?php echo
address ?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtCityltemgtlt/em
gtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput type"text"
name"city" value"lt?php echo city ?gt"
/gt lt/labelgtlt/tdgt lt/trgt
27
Lanjutan Nama File Insert.php
lttr align"Right"gt lttd colspan"2"gtltlabelgt ltinput
type"submit" name"submit" value"Insert
Records"gt lt/labelgtlt/tdgt lt/trgt lt/tablegt lt/formgt lt/b
odygt lt/htmlgt lt?php include('config.php') if
(isset(_POST'submit')) name
mysql_real_escape_string(htmlspecialchars(_POST'
name')) address mysql_real_escape_string(html
specialchars(_POST'address')) city
mysql_real_escape_string(htmlspecialchars(_POST'
city')) if (name '' address ''
city '')
28
Lanjutan Nama File Insert.php
error 'Please enter the details!' valid(name,
address, city,error) else mysql_query("IN
SERT employee SET name'name',
address'address', city'city'") or
die(mysql_error()) header("Location
view.php") else valid('','','','') ?gt
29
Nama File Edit.php
lt?php function valid(id, name, address,city,
error) ?gt lthtmlgt ltheadgt lttitlegtEdit
Recordslt/titlegt lt/headgt ltlink href"style.css"
rel"stylesheet" type"text/css"gt ltbodygt lt?php if
(error ! '') echo 'ltdiv style"padding4px
border1px solid red colorred"gt'.error.'lt/divgt
' ?gt ltform action"" method"post"gt ltinput
type"hidden" name"id" value"lt?php echo id
?gt"/gt lttable border"1"gt lttrgt lttd
colspan"2"gtltbgtltfont color'Red'gtEdit Records
lt/fontgtlt/bgtlt/tdgt lt/trgt
30
Lanjutan Nama File Edit.php
lttrgt lttd width"179"gtltbgtltfont color'663300'gtName
ltemgtlt/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"name" value"lt?php echo name
?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtAddressltemgtlt
/emgtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput
type"text" name"address" value"lt?php echo
address ?gt" /gt lt/labelgtlt/tdgt lt/trgt lttrgt lttd
width"179"gtltbgtltfont color'663300'gtCityltemgtlt/em
gtlt/fontgtlt/bgtlt/tdgt lttdgtltlabelgt ltinput type"text"
name"city" value"lt?php echo city ?gt"
/gt lt/labelgtlt/tdgt lt/trgt lttr align"Right"gt lttd
colspan"2"gtltlabelgt ltinput type"submit"
name"submit" value"Edit Records"gt lt/labelgtlt/tdgt
lt/trgt lt/tablegt lt/formgt lt/bodygt lt/htmlgt lt?php
31
Lanjutan Nama File Edit.php
include('config.php') if (isset(_POST'submit'
)) if (is_numeric(_POST'id')) id
_POST'id' name mysql_real_escape_string(htm
lspecialchars(_POST'name')) address
mysql_real_escape_string(htmlspecialchars(_POST'
address')) city mysql_real_escape_string(html
specialchars(_POST'city')) if (name ''
address '' city '') error 'ERROR
Please fill in all required fields!' valid(id,
name, address,city, error) else mysql_que
ry("UPDATE employee SET name'name',
address'address' ,city'city' WHERE
id'id'") or die(mysql_error()) header("Location
view.php") else echo 'Error!'
32
Lanjutan Nama File Edit.php
else if (isset(_GET'id')
is_numeric(_GET'id') _GET'id' gt 0) id
_GET'id' result mysql_query("SELECT
FROM employee WHERE idid") or
die(mysql_error()) row mysql_fetch_array(resu
lt) if(row) name row'name' address
row'address' city row'city' valid(id,
name, address,city,'') else echo "No
results!" else echo 'Error!' ?gt
33
Nama File Delete.php
lt?php include('config.php') if
(isset(_GET'id') is_numeric(_GET'id'))
id _GET'id' result mysql_query("DELETE
FROM employee WHERE idid") or
die(mysql_error()) header("Location
view.php") else header("Location
view.php") ?gt
34
Nama File style.css
body color2e6ab1 table
border-collapse collapse th
background-color 2e6ab1 padding-left
14px padding-right 8px border 1px solid
969BA5 text-alignleft colorffffff
td background-color F0F0F0 padding-left
8px padding-right 8px padding-top
2px padding-bottom 2px border 1px solid
969BA5 color2e6ab1 Input, select
color2e6ab1
35
Contoh Kasus - 2
CREATE TABLE mhs ( NIM varchar(16) NOT NULL
default '', Nama varchar(145) NOT NULL default
'', TglLahir date NOT NULL default
'0000-00-00', Kelas varchar(15) NOT NULL
default '', Jrs char(3) NOT NULL default '',
PRIMARY KEY (NIM), KEY NIM (NIM) )
TYPEMyISAM INSERT INTO mhs VALUES
('091011152620001', 'Pradani', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620002', 'Atika', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620003', 'Danny', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620004', 'Debie', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620005', 'Cintya', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620006', 'Asep', '1966-07-10', 'SK-4',
'262') INSERT INTO mhs VALUES ('091011152620007',
'Joko', '1966-07-10', 'SK-4', '262') INSERT
INTO mhs VALUES ('091011152620008', 'Acong',
'1966-07-10', 'SK-4', '262') INSERT INTO mhs
VALUES ('091011152620009', 'Ucok', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620010', 'Baba', '1966-07-10', 'SK-4',
'262') INSERT INTO mhs VALUES ('091011152620011',
'Khan', '1966-07-10', 'SK-4', '262') INSERT
INTO mhs VALUES ('091011152620012', 'Nere',
'1966-07-10', 'SK-4', '262') INSERT INTO mhs
VALUES ('091011152620013', 'Sania', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620014', 'Riani', '1966-07-10',
'SK-4', '262') INSERT INTO mhs VALUES
('091011152620015', 'Ryan', '1966-07-10', 'SK-4',
'262') INSERT INTO mhs VALUES ('091011152620016',
'Wilujeng', '1966-07-10', 'SK-4', '262')
Nama Database dbmhs Script Table mahasiswa
36
Nama File BrowseMhs.php
?gtphp ltfont color"FF0000"gt lt? conmysql_connec
t("localhost","root","") dbmysql_select_db("dbm
hs") sql"Select from mhs" hasilmysql_query
(sql) while (rowmysql_fetch_array(hasil))
echo "rowNIM-rowNama-rowTglLahir-
rowKelas-rowJrs" echo "lta
href'editmhs.php?NIMrowNIM'gt Edit lt/agt "
echo "lta href'deletemhs.php?NIMrowNIM'gt
Deletelt/agt lthrgt" ?gt
37
Nama File editmhs.php
lt?php nim_REQUESTNIM conmysql_connect("lo
calhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mhs where NIM'nim'
" hasilmysql_query(sql) rowmysql_fetch_arra
y(hasil) namarowNama tgllahirrowTglLah
ir kelasrowKelas jrsrowJrs ?gt
38
Lanjutan Nama File editmhs.php
ltfont color"FF0000"gt ltform action""
method"GET"gt NIM ltinput type"text" name"NIM"
value"lt? echo nim ?gt "gtltbrgt Nama ltinput
type"text" name"Nama" value"lt? echo nama ?gt
"gtltbrgt Tanggal Lahir ltinput type"text"
name"TglLahir" value"lt? echo tgllahir ?gt
"gtltbrgt Kelas ltinput type"text" name"Kelas"
value"lt? echo kelas ?gt "gtltbrgt Jurusan ltinput
type"text" name"Jrs" value"lt? echo jrs ?gt
"gtltbrgt ltinput type"submit" name"simpan"
value"Update"gt ltinput type"reset" name"batal"
value"Cancel"gt lt/formgt
39
Lanjutan Nama File editmhs.php
lt? if (_REQUESTsimpan'Update')
echo "Proses Updating..!" nim_REQUESTNIM
nama_REQUESTNama tgllahir_REQUESTTg
lLahirkelas_REQUESTKelas
jrs_REQUESTJrs sql"update mhs set
NIM'nim', Nama'nama', TglLahir'tgllahir',
Kelas'kelas', Jrs'jrs' where NIM'nim'
" hasilmysql_query(sql) echo
"Berhasil di Update..!" ?gt lthrgtlta
href"ListMhs.php"gtBacklt/agt
40
Nama File deletemhs.php
lt?php nim_REQUESTNIM conmysql_connect("loc
alhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mhs where NIM'nim'
" hasilmysql_query(sql) rowmysql_fetch_arra
y(hasil) namarowNama tgllahirrowTglLah
ir kelasrowKelas jrsrowJrs ?gt
41
Lanjutan Nama File deletemhs.php
ltfont " color"FF0000"gt ltform action""
method"GET"gt NIM ltinput type"text" name"NIM"
value"lt? echo nim ?gt "gtltbrgt Nama ltinput
type"text" name"Nama" value"lt? echo nama ?gt
"gtltbrgt Tanggal Lahir ltinput type"text"
name"TglLahir" value"lt? echo tgllahir ?gt
"gtltbrgt Kelas ltinput type"text" name"Kelas"
value"lt? echo kelas ?gt "gtltbrgt Jurusan ltinput
type"text" name"Jrs" value"lt? echo jrs ?gt
"gtltbrgt ltinput type"submit" name"simpan"
value"Delete"gt ltinput type"reset" name"batal"
value"Cancel"gt lt/formgt
42
Lanjutan Nama File deletemhs.php
lt? if (_REQUESTsimpan'Delete')
echo "Proses Deleting..!" sql" delete
from mhs where NIM'nim' "
hasilmysql_query(sql) echo "Berhasil
di Hapus..!" ?gt lta href"ListMhs.php"gtBacklt
/agt
43
Nama File menu.php
ltp align"left"gt ltbr/gt lt?php echo "lta
href\"addmhs.php\"gtAdd Mhslt/agtltbr/gt" echo "lta
href\"browsemhs.php\"gtBrowse Mhslt/agtltbr/gt"
echo "lta href\"Listmhs.php\"gtList
Mhslt/agtltbr/gt" echo "lta href\"FormLogin.php\"gtEx
itlt/agtltbr/gt" echo "ltbr/gt" echo "ltbr/gt" ?gt
lt/pgt
44
Nama File addmhs.php
lt?php conmysql_connect("localhost","root","")
dbmysql_select_db("dbmhs") ?gt ltfont
color"FF0000"gt ltform action""
method"GET"gt NIM ltinput type"text"
name"NIM"gtltbrgt Nama ltinput type"text"
name"Nama"gtltbrgt Tanggal Lahir ltinput type"text"
name"TglLahir"gtltbrgt Kelas ltinput type"text"
name"Kelas"gtltbrgt Jurusan ltinput type"text"
name"Jrs"gtltbrgt ltinput type"submit"
name"simpan" value"Add"gt ltinput type"reset"
name"batal" value"Cancel"gt lt/formgt
lt? if (_REQUESTsimpan'Add') echo
"Proses Adding..!" nim_REQUESTNIMnama
_REQUESTNama tgllahir_REQUESTTglLahir
kelas_REQUESTKelas jrs_REQUESTJrs
sql"Insert into mhs values ('nim', 'nama',
'tgllahir', 'kelas', 'jrs')"
hasilmysql_query(sql) echo "Berhasil
di Disimpan..!" ?gt lthrgtlta hrefmenu.php"gtBac
klt/agt
45
Listmhs.php
ltfont color"FF0000"gt lt? conmysql_connect("loca
lhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mhs" hasilmysql_query(sql)
while (rowmysql_fetch_array(hasil)) echo
"rowNIM-rowNama-rowTglLahir-
rowKelas-rowJrslthrgt" ?gt lta
hrefmenu.phpgtBacklt/agt
46
CREATE TABLE mtk ( KodeMK varchar(10) NOT NULL
default '', NamaMK varchar(145) NOT NULL
default '', SKS int, KodeJrs char(3) NOT NULL
default '', PRIMARY KEY (KodeMK), KEY
KodeMK (KodeMK) ) TYPEMyISAM INSERT INTO mtk
VALUES ('KKKI12001', 'Pancasila', '2',
'263') INSERT INTO mtk VALUES ('KKKI12002',
'Agama', '2', '263') INSERT INTO mtk VALUES
('KKKI12003', 'Bahasa Indonesia', '2',
'263') INSERT INTO mtk VALUES ('KKKI12004',
'Kewarganegaraan', '2', '263') INSERT INTO mtk
VALUES ('KKKI12005', 'Etika Profesi', '2',
'263')
Script Table matakuliah
47
CREATE TABLE ambilmk ( nim varchar(16) NOT NULL
default '', kodeMK varchar(10) NOT NULL default
'', nilai char(2) defalt NULL, PRIMARY KEY
(nim,kodeMK) ) TYPEMyISAM INSERT INTO
ambilmk VALUES ('091011152620003', 'KKKI12001',
'A') INSERT INTO ambilmk VALUES
('091011152620003', 'KKKI12002', 'A') INSERT
INTO ambilmk VALUES ('091011152620003',
'KKKI12003', 'B') INSERT INTO ambilmk VALUES
('091011152620003', 'KKKI12004', 'A') INSERT
INTO ambilmk VALUES ('091011152620003',
'KKKI12005', 'C') INSERT INTO ambilmk VALUES
('091011152620016', 'KKKI12002', 'A') INSERT
INTO ambilmk VALUES ('091011152620016',
'KKKI12003', 'B') INSERT INTO ambilmk VALUES
('091011152620016', 'KKKI12005', 'A')
Script Table ambilmk
48
ltfont color"FF0000"gt lt? conmysql_connect("loca
lhost","root","") dbmysql_select_db("dbmhs")
sql"Select from mtk" hasilmysql_query(sql)
while (rowmysql_fetch_array(hasil)) echo
"rowKodeMK-rowNamaMK-rowSKS-rowKodeJrs
" echo "lta href'editmtk.php?KodeMKrowKodeMK
'gt Edit lt/agt " echo "lta href'deletemtk.php?
KodeMKrowKodeMK'gt Deletelt/agt lthrgt" ?gt
49
Nama File FormInputkrs.php
lt?php mysql_connect("localhost", "root",
"") mysql_select_db("dbmhs") sql"Select
from mhs" hasilmysql_query(sql) ?gt ltfont
size"" color"FF0000"gt ltform method"post"
action"simpan.php"gt Nomor BP ltselect
name"nim"gt lt? while (rowmysql_fetch_array(hasi
l)) echo "ltoption valuerowNIMgtrowNIMlt/opt
iongt" echo "lt/selectgtltbrgtltbrgt" query
"SELECT FROM mtk" hasil mysql_query(query)
no 1 while (data mysql_fetch_array(hasil)
) echo "ltinput type'checkbox'
value'".data'KodeMK'."' name'mk".no."' /gt
".data'KodeMK'.' - '.data'NamaMK'."ltbr
/gt" no ?gt ltbrgt ltinput type"hidden"
name"jumMK" value"lt?php echo no-1 ?gt"
/gt ltinput type"submit" name"submit"
value"Ambil" /gt lt/formgt
50
Nama File simpan.php
lt?php mysql_connect("localhost", "root",
"") mysql_select_db("dbmhs") nim
_REQUEST'nim' jumMK _POST'jumMK' for(i
1 i lt jumMK i) mk
_POST'mk'.i if (!empty(mk))
query "INSERT INTO ambilMK VALUES('nim',
'mk', '-')" mysql_query(query)
echo "Terimakasih sudah memilih
matakuliah" ?gt
51
FormNilai.php
lt?php header('Content-typetext/vnd.wap.wml') ech
o('lt?xml version"1.0"?gt') echo('lt!DOCTYPE wml
PUBLIC "-//WAPFORUM// DTD WML 1.1/EN"gt') mysql_co
nnect("localhost", "root", "") mysql_select_db("d
bmhs") sql"Select from mtk" hasilmysql_que
ry(sql) ?gt ltcard id"KRS" title"Form
Nilai"gt ltfont size"" color"FF0000"gt ltform
method"post" action"simpan1.php"gt Nomor BP
ltselect name"kodemk"gt lt? while
(rowmysql_fetch_array(hasil)) echo "ltoption
valuerowKodeMKgtrowKodeMKlt/optiongt" echo
"lt/selectgtltbrgtltbrgt" query "SELECT FROM
ambilmk, mhs, mtk where ambilmk.nimmhs.NIM and
ambilmk.kodeMKmtk.KodeMK order by
mhs.NIM" hasil mysql_query(query) no
1 lt/cardgt lt/wmlgt
52
while (data mysql_fetch_array(hasil))
echo "ltselect name'nl".no."'gt" echo
"ltoption value'A'gtAlt/optiongt" echo "ltoption
value'B'gtBlt/optiongt" echo "ltoption
value'C'gtClt/optiongt" echo "ltoption
value'D'gtDlt/optiongt" echo "ltoption
value'E'gtElt/optiongt" echo "ltoption
value'TL'gtTLlt/optiongt" echo "ltinput
type'hidden' value'".data'nim'."'
name'nim".no."' /gt" echo "ltinput
type'hidden' value'".data'kodeMK'."'
name'mk".no."' /gt ".data'nim'.' -
'.data'NamaMK'.' - '.data'kodeMK'."ltbr/gt"
no ?gt lt/selectgt ltbrgt ltinput type"hidden"
name"jumMK" value"lt?php echo no-1 ?gt"
/gt ltinput type"submit" name"submit"
value"Ambil" /gt lt/formgt
53
simpan1.php
lt? header('Content-typetext/vnd.wap.wml') echo('
lt?xml version"1.0"?gt') echo('lt!DOCTYPE wml
PUBLIC "-//WAPFORUM// DTD WML 1.1/EN"gt') mysql_co
nnect("localhost", "root", "") mysql_select_db("d
bmhs") jumMK _POST'jumMK' for(i 1 i
lt jumMK i) mk _REQUEST'mk'.i
nim _REQUEST'nim'.i nl
_REQUEST'nl'.i if (!empty(mk))
query "update ambilMK set nilai'nl'
where nim'nim' and kodeMK'mk'"
mysql_query(query) echo "Terimakasih
sudah memilih matakuliah" ?gt
54
Nama File ListNilai.php
ltbgtltbiggtDAFTAR NILAI MAHASISWA lt? conmysql_conne
ct("localhost","root","") dbmysql_select_db("db
mhs") sql"SELECT mhs.NIM, Nama, mtk.KodeMK,
NamaMK, SKS, nilai FROM ambilmk, mhs, mtk where
ambilmk.nimmhs.NIM and ambilmk.kodeMKmtk.KodeMK
order by mhs.NIM" hasilmysql_query(sql) nim
'091011152620001' bb0tbb0tsks0nu0 ech
o "ltfont size-5 colorFF0000gtltbrgtlthrgt" while
(rowmysql_fetch_array(hasil))
55
Lanjutan Nama File ListNilai.php
nu if (nim!rowNIM)
if (nugt1)
echo "ltbgtIndek Prestasi " echo
number_format(ip,2,',','.')
echo "ltbrgtlthrgt"
bb0tbb0tsks0nu0
if (rownilai'A') mutu4
elseif (rownilai'B') mutu3
elseif (rownilai'C') mutu2 elseif
(rownilai'D') mutu1 elseif
(rownilai'E') mutu0 elseif
(rownilai'TL) mutu'0'
56
Lanjutan Nama File ListNilai.php
bbmuturowSKS tskstsksrowSKS
tbbtbbbb if (tbbgt0)
iptbb/tsks echo "rowNIM-rowNama-row
KodeMK-rowNamaMK-rowSKS-rownilai-mutu-
bblthrgt" nimrowNIM echo "ltbgtIndek
Prestasi " echo number_format(ip,2,',','.') ec
ho "lthrgt" ?gt
57
Nama File .php
58
Nama File .php
59
Nama File .php
60
Nama File .php
61
Nama File .php
62
Nama File .php
63
Nama File .php
64
Nama File .php
65
Nama File .php
66
Nama File .php
67
Nama File .php
68
Nama File .php
69
Nama File .php
70
Nama File .php
71
Nama File .php
72
Nama File .php
73
Nama File .php
74
Nama File .php
75
Nama File .php
76
Nama File .php
77
Nama File .php
78
Nama File .php
79
Nama File .php
80
Nama File .php
81
Nama File .php
82
Nama File .php
83
Nama File .php
84
Nama File .php
85
Nama File .php
86
Nama File .php
87
Nama File .php
88
Nama File .php
89
Nama File .php
90
Nama File .php
91
Nama File .php
92
Nama File .php
93
Nama File .php
94
Nama File .php
95
Nama File .php
96
Nama File .php
97
Nama File .php
98
Nama File .php
99
Nama File .php
100
Nama File .php
101
Nama File .php
102
Nama File .php
Write a Comment
User Comments (0)