Help with not displaying other subcategories

Thanks for your reply.
Does this look like the “getsubcategories.php” file? Here’s the subcategory portion:

<?php
 .................................
 .................................


if ($first == 'add_sub_category') {
    $data['status'] = 400;
    $data['message'] = 'Please check your details';
    $add = false;
    $insert_data = array();
    foreach ($pt->langs as $key => $lang) {
        if (!empty($_POST[$lang])) {
            $insert_data[$lang] = PT_Secure($_POST[$lang]);
            $add = true;
        }
    }
    $count = $db->where('lang_key',PT_Secure($_POST['key']))->getValue(T_LANGS,'COUNT(*)');
    if ($count == 0) {
        $add = false;
    }
    if ($add == true && !empty($insert_data)) {
        $insert_data['type'] = PT_Secure($_POST['key']);
        $id = $db->insert(T_LANGS,$insert_data);
        $db->where('id',$id)->update(T_LANGS,array('lang_key' => 'sub__'.$id));
        $data = array('status' => 200);
    }
}

if ($first == 'delete_sub_category') {
    $data['status'] = 400;
    if (!empty($_POST['sub_id'])) {
        if ($_POST['sub_id'] != 'other') {
            $db->where('lang_key',PT_Secure($_POST['sub_id']))->delete(T_LANGS);
            $db->where('sub_category',PT_Secure($_POST['sub_id']))->update(T_VIDEOS,array('sub_category' => ''));
            $data['status'] = 200;
        }
    }
}
// if ($first == 'save_edited_sub') {
//     $data['status'] = 400;
//     if ((!empty($_POST['sub_id']) && is_numeric($_POST['sub_id']) && $_POST['sub_id'] > 0) && !empty($_POST['text'])) {
//         $cat_id = PT_Secure($_POST['sub_id']);
//         $sub_name = PT_Secure($_POST['text']);
//         $db->where('id',$cat_id)->update(T_SUB_CATEGORIES,array('name' => $sub_name));
//         $data['status'] = 200;
//         $data['text'] = $sub_name;
//     }
// }

Any additional guidance is appreciated

No, it looks too complex to be that.

Basically when you call the php file and give it a category, it needs to give the appropriate JSON-formatted subcategories. For example:

URL address: getsubcategories.php?category=fruit

Text output:
["Apple","Banana","Orange","Watermelon"]

I think what Paul means is that you would have just a short PHP script which does exactly one thing - get the category reference from the information you pass into it (in the URL in his example), do a single query to retrieve the subcategories, and return them or some means of indicating that there are none. If this is a feature you are adding to your site, then you may well not already have that script, you may need to write it from scratch.

You might be able to add some flags to existing code to strip out just the bit that retrieves a list of subcategories, but then you’re shoe-horning stuff into your existing code (which you mention you didn’t write) and it’s fairly complex already. So it might be better for you to write this one from scratch - retrieve the search parameter from the URL, validate it, run the query, package the results into a JSON string, echo it. Once you’ve got that working, you can work on calling it from your page using Ajax.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.