In general, when adding a product to the store, the user selects a section.

echo 'Раздел: <select name="cat">'; $res = mysql_query('SELECT * FROM `shop_cat` ORDER BY `realid`;'); while($row = mysql_fetch_assoc($res)) { echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; } echo '</select><br/>'; 

When choosing a valid first section, you need to make it appear below the subsection with the categories of the first section. If the second - then the subsection, respectively, with the categories of the second section.

    2 answers 2

    Download all the categories (I think they will not take too much and it will not take long), then apply the jQuery.treeview () plugin to the list;

    UPD

    jquery.treeview ()

    • What kind of plugin? - vitagame
      <script> function processStateChange(){ if (request.readyState == 4){ contentDiv = document.getElementById(dest); if (request.status == 200) { response = request.responseText; contentDiv.innerHTML = response; } else { contentDiv.innerHTML = "Error: Status "+request.status; } } } // Это функция получет содермжимое от файла URL и разместить на элемент по АйДи destination function loadHTML(URL, destination){ dest = destination; URL=URL+'&cache='+(new Date().getTime()); if (window.XMLHttpRequest){ request = new XMLHttpRequest(); request.onreadystatechange = processStateChange; request.open("GET", URL, true); request.send(null); } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); if (request) { request.onreadystatechange = processStateChange; request.open("GET", URL, true); request.send(); } } } <? echo 'Раздел: <select name="cat" onchange="loadHTML(\'podrazdel.php?razdel\' + this.selectedIndex, \'razdelDiv\') ">'; $res = mysql_query('SELECT * FROM `shop_cat` ORDER BY `realid`;'); while($row = mysql_fetch_assoc($res)) { echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; } echo '</select><br/>'; ?> <div id='razdelDiv'></div> /////////////// /// Теперь podrazdel.php <? echo 'ПодРаздел: <select name="sub_cat" >'; $res = mysql_query('SELECT * FROM `shop_sub_cat` where cat_id='.$HTTP_GET_VARS["razdel"] .' ORDER BY `realid`;'); while($row = mysql_fetch_assoc($res)) { echo '<option value="'.$row['id'].'">'.$row['name'].'</option>'; } echo '</select><br/>'; ?> 
    • I certainly did differently. And easier. Well, so try. - vitagame
    • Does not work. Subcategories are not displayed. - vitagame
    • and the table of subcategories is called. I conditionally shop_sub_cat wrote ... - ilyosbey
    • I replaced it with mine. Still does not work. - vitagame
    • and on the file podrazdel.php there is a connection to the database? - ilyosbey