Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CAT ID PARENT_ID
- ------+----------
- 1 0
- 2 0
- 3 1
- 4 1
- 5 3
- 6 2
- Cat 1
- Subcat1
- SubCat2
- SubSubcat1
- Cat 2
- Subcat1
- <?php
- require_once 'config.php';
- ?>
- <?php header('Content-Type: text/html; charset=UTF-8'); ?>
- <?php
- $username = "qzd708";
- $password = "aR689193";
- $hostname = "qzd708.laclonadora.com";
- $databasename = "qzd708";
- $parent_id=0;
- $salida=" ";
- $mysqli = new mysqli($hostname , $username, $password, $databasename);
- $ruta="";
- //connect to mysql and select db
- $conn = mysqli_connect($hostname , $username, $password, $databasename);
- if( !empty($conn->connect_errno)) {die("Error " . mysqli_error($conn));}
- echo "<select>";
- echo "<option value='' disabled selected>--Seleccione CategorÃa--</option>";
- //call the recursive function to print category listing
- category_tree(0);
- echo "</select>";
- //
- //echo gettheparent(168);
- //Recursive php function
- function category_tree($catid){
- global $conn;
- $sql = "select * from oc_category where parent_id ='".$catid."'";
- $result = $conn->query($sql);
- while($row = mysqli_fetch_object($result)):
- $i = 0;
- //$ruta=gettheparent(168);
- if ($i == 0) {
- echo "<option value='". $row->category_id;echo "'>". gettheparent ($row->category_id) . getthename($row->category_id);
- category_tree($row->category_id);
- echo "</option>";
- $i++;
- }
- if ($i > 0) {
- //echo '</ul>';
- //$ruta=gettheparent($catid);
- }
- endwhile;
- }
- function category_tree_li($catid){
- global $conn;
- $sql = "select * from oc_category where parent_id ='".$catid."'";
- $result = $conn->query($sql);
- while($row = mysqli_fetch_object($result)):
- $i = 0;
- if ($i == 0) {
- echo '<ul>';
- echo '<li>' . $row->category_id;
- category_tree_li($row->category_id);
- echo '</li>';
- $i++;
- }
- if ($i > 0) {
- echo '</ul>';
- }
- endwhile;
- }
- //category_tree_li(0);
- //close the connection
- mysqli_close($conn);
- function getthename ($category_id){
- if ($category_id !=0) {
- $username = "qzd708";
- $password = "aR689193";
- $hostname = "qzd708.laclonadora.com";
- $databasename = "qzd708";
- $mysqli = new mysqli($hostname , $username, $password, $databasename);
- if (mysqli_connect_errno()) {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();
- }
- $query = "SELECT name FROM oc_category_description WHERE category_id = '".$category_id."'";
- $result = $mysqli->query($query);
- while($row = $result->fetch_array())
- {
- $rows[] = $row;
- }
- foreach($rows as $row)
- {
- $salida.=" - ";
- $salida.= utf8_encode($row["name"]);
- return $salida;
- }
- $result->close();
- $mysqli->close();
- }
- }
Add Comment
Please, Sign In to add comment