Created
May 28, 2011 04:16
-
-
Save radityopw/996594 to your computer and use it in GitHub Desktop.
multiple kategori view as <ul><li>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysql_pconnect("server location","server user","server pass"); | |
mysql_select_db("yourdb",$con); | |
function list_all_kategori($parent_id,$level=0){ | |
global $con; | |
$sql = "SELECT * FROM kategori WHERE parent_id='".$parent_id."'"; | |
$res = mysql_query($sql,$con); | |
$data = array(); | |
while($row = mysql_fetch_assoc($res)){ | |
$data[] = $row; | |
} | |
if(count($data) == 0){ | |
return ""; | |
}else{ | |
$str = ""; | |
for($i=0;$i<$level;$i++){ | |
$str.="\t"; | |
} | |
$str .= "<ul>\n"; | |
foreach($data as $row){ | |
for($i=0;$i<$level;$i++){ | |
$str.="\t"; | |
} | |
$str.="<li>".$row['nama']."</li>\n".list_all_kategori($row['id'],($level+1)); | |
} | |
$str.="\n"; | |
for($i=0;$i<$level;$i++){ | |
$str.="\t"; | |
} | |
return $str."</ul>\n"; | |
} | |
} | |
?> | |
<html> | |
<body> | |
<?php echo list_all_kategori(0); ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment