2017-06-26 1 views
0

私は30k以上のカテゴリのショップを持っています。カテゴリの量に合わせてデザインされていない製品編集ページのカテゴリ選択を処理する方法は管理ではほとんど不可能です。非常に長く、時にはクラッシュすることもあります。それは単純な選択ボックスであり、何ができるのだろうか?カテゴリのphp出力

これが機能するには、ajaxが必要ですか?

<?php function custom_catalog_tree($category_id=0, $depth=1, $count=0) { 

$output = ''; 

if ($category_id == 0) { 
$output .= '<div class="checkbox" id="category-id-'. $category_id .'"><label>'. functions::form_draw_checkbox('categories[]', '0', (isset($_POST['categories']) && in_array('0', $_POST['categories'], true)) ? '0' : false, 'data-name="'. htmlspecialchars(language::translate('title_root', 'Root')) .'" data-priority="0"') .' '. functions::draw_fonticon('fa-folder', 'title="'. language::translate('title_root', 'Root') .'" style="color: #cccc66;"') .' ['. language::translate('title_root', 'Root') .']</label></div>' . PHP_EOL; 
} 

// Output categories 
$categories_query = database::query(
    "select c.id, ci.name 
    from ". DB_TABLE_CATEGORIES ." c 
    left join ". DB_TABLE_CATEGORIES_INFO ." ci on (ci.category_id = c.id and ci.language_code = '". language::$selected['code'] ."') 
    where c.parent_id = '". (int)$category_id ."' 
    order by c.priority asc, ci.name asc;" 
); 

while ($category = database::fetch($categories_query)) { 
    $count++; 

    $output .= ' <div class="checkbox"><label>'. functions::form_draw_checkbox('categories[]', $category['id'], true, 'data-name="'. htmlspecialchars($category['name']) .'" data-priority="'. $count .'"') .' '. functions::draw_fonticon('fa-folder fa-lg', 'style="color: #cccc66; margin-left: '. ($depth*1) .'em;"') .' '. $category['name'] .'</label></div>' . PHP_EOL; 

    if (database::num_rows(database::query("select * from ". DB_TABLE_CATEGORIES ." where parent_id = '". $category['id'] ."' limit 1;")) > 0) { 
    $output .= custom_catalog_tree($category['id'], $depth+1, $count); 
    } 
} 

database::free($categories_query); 

return $output; 
} 

echo custom_catalog_tree(); 
?> 
+0

あなたが本当に選択ボックスで30Kオプションを表示する必要がありますか? – modsfabio

+0

管理バックエンド用です。私はこの量のカテゴリーを持っていますし、はい、私は様々なカテゴリーに製品に付ける必要があります。 – medgalys

+1

30k以上のカテゴリーのショップ...?それらをすべてより速く表示しようとするよりも、あなたのショップ/カテゴリーを再設計するべきだと思います。人間の脳は30kカテゴリを扱うことはできません。価値はありません。カテゴリについて本当に話しているのですか、タグのようなものについてもっと話していますか? – Twinfriends

答えて

0

は、私が代わりに選択ボックスの検索ボックスを作るためにあなたをお勧めします:

は、ここでは、コードです。可能であれば、ajaxを使用して商品カテゴリを検索するためのクエリを書き留めます。 select * from table_nameを使用して検索クエリを作成します。%your_value%

+0

私はAjax検索を選択ボックスの代わりに管理しましたが、ページ更新後にどのカテゴリがチェックされているかを表示することはできません。ここに私のコードの一部があります:

' + '
'+ result.description +'
' + '' + \t \t \t \t \t '' – medgalys

0

などのカテゴリは、Select2プラグインを使用して簡単に処理できます。 提案ドロップダウンを提供します。ここで、ユーザーはドロップダウン値を入力してフィルタリングできます。

サーバー側では、名前でカテゴリを取得するためにWebサービスを作成する必要があります。リモートデータにのロードセクション

ゴー、

https://select2.github.io/examples.html#data-ajax