PHP &

0 Cevap php

Ben kategorileri görüntüleyen bir komut dosyası var ama komut kullanıcı 1'den birçok kategoride değişebilir hangi aldı sadece belirli kategorileri görüntülemek istiyorum. Ben bu sorunu gidermek için benim komut için ne gerekiyor? Bir örnek bir sürü yardımcı olacaktır.

İşte benim PHP betik.

function make_list ($parent = 0, $parent_url = '') {
    global $link;
    echo '<ol>';

    foreach ($parent as $id => $cat) {
        $url = $parent_url . $cat['url'];
        echo '<li><a href="' . $url . '" title="' . $cat['category'] . ' Category Link">' . $cat['category'] . '</a>';          

        if (isset($link[$id])) {
            make_list($link[$id], $url); // $url adds url value to sub categories
        }               
        echo '</li>';
    }       
    echo '</ol>';
}

$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT * FROM categories ORDER BY parent_id, category ASC");
if (!$dbc) {
    print mysqli_error();
} 

$link = array();

while (list($id, $parent_id, $category, $url) = mysqli_fetch_array($dbc)) {
    $link[$parent_id][$id] =  array('category' => $category, 'url' => $url);
}

make_list($link[0]);

İşte benim MySQL tablodur.

CREATE TABLE categories ( 
id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
parent_id INT UNSIGNED NOT NULL DEFAULT 0, 
category VARCHAR(255) NOT NULL, 
url VARCHAR(255) NOT NULL,
depth INT NOT NULL DEFAULT 0, 
PRIMARY KEY (id), 
INDEX parent (parent_id),
UNIQUE KEY(parent_id, url)
);

İşte ben görüntülemek istediğiniz kategorileri yorumladı kategoriler listemde.

Antiques
    Antiquities
    Architectural & Garden
        Asian Antiques
        Books & Manuscripts
            Decorative Arts
                Ethnographic
                    Furniture // I want to select this category
Home & Hearth
Linens & Textiles
Restoration & Care // I want to select this category
Rugs & Carpets // I want to select this category
Science & Medicine
Silver // I want to select this category
Reproduction Antiques

0 Cevap