Beranda > php, Programing > Dynamic Parenting Menu

Dynamic Parenting Menu

Kali ini kita buat dinamic parenting menu, apa yah, itu loh menu model hierarki, atau bisa juga buat site map web, ya udah coba aja dilanjut, pertama-tama buat table ini :

DROP TABLE IF EXISTS `menu`;

CREATE TABLE `menu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent` int(11) NOT NULL,
`nama` varchar(60) NOT NULL,
`link` varchar(50) NOT NULL,
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=latin1;

<?php
$kon = mysql_connect(“localhost”,”root”,””);
$db = mysql_select_db(“parenting_menu”);

function show($id = ”){
//$where = “”;
if(strlen($id) > 0) $where = ” WHERE parent=’$id'”;
$sql = “SELECT * FROM menu $where”;
$res = mysql_query($sql);
$num = mysql_num_rows($res);

$i = ‘0’;
while($row = mysql_fetch_object($res)){

/*if($i == 0){
echo “\n<ul type=\”disc\”>”;
}

$i++;*/

echo “<ul type=\”circle\”>”;

echo “\n\t\t<li>”;

echo “$row->nama”;

//echo “&nbsp;”.$i;

show($row->id);

echo “</li>”;

echo “</ul>”;

/*if($i == $num) {
echo “\n</ul>”;
}*/

}
}
echo show(“0”);

  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: