host .";dbname=" . $config->db, $config->user, $config->password); $show_input = true; if (isset($_POST['sort_id'])) { $id = $_POST['sort_id']; if (ctype_digit($id)) { $sql = "SELECT category_id, category_name FROM " . $config->dbprefix . "hikashop_category " . "WHERE category_parent_id = " . $id ; $query = $dbh->query($sql); $categories = $query->fetchAll(PDO::FETCH_OBJ); if (count($categories) == 0) { echo "No Matches for Category ID: " . $id . "
\n"; } else { $show_input = false; function ignore_the_cmp($a, $b) { static $excludes = '/^the\s+/i'; // Add excluded words here return strcasecmp( preg_replace($excludes, '', $a->category_name), preg_replace($excludes, '', $b->category_name) ); } usort($categories, "ignore_the_cmp"); $order = 1; foreach($categories as $category) { // echo($category->category_name . "
\n"); $sql = "UPDATE " . $config->dbprefix . "hikashop_category SET category_ordering = " . $order . " WHERE category_id = " . $category->category_id; echo("running: " . $sql . "
\n"); $query = $dbh->query($sql); $order = $order + 1; } } } else { echo "Invalid Category ID: " . $id . "
\n"; } } if ($show_input) { ?>
Category ID:
Product Categories for Reference

"); echo("\n"); $sql = "SELECT category_id, category_name FROM " . $config->dbprefix . "hikashop_category " . "WHERE category_parent_id = 2"; $query = $dbh->query($sql); $categories = $query->fetchAll(PDO::FETCH_OBJ); foreach($categories as $category) { echo("\n"); } echo("
" . $category->category_id . "" . $category->category_name . "
\n"); } ?>