Ejemplo n.º 1
0
function get_children_id($id)
{
    global $db, $children_id;
    $table_name = "dataclass";
    $field_id = "id";
    $field_parent_id = "parent_id";
    if (!$children_id) {
        $children_id = array();
        //添加当前分类的ID
        $children_id[] = $id;
    }
    $sql = "select " . $field_id . " from " . $table_name . " where " . $field_parent_id . " = " . $id;
    $children_data = $db->get_results($sql, ARRAY_A);
    foreach ($children_data as $v) {
        $children_id[] = intval($v[$field_id]);
        get_children_id($v[$field_id]);
    }
}
Ejemplo n.º 2
0
<?php

require 'init.php';
require_once '../comm_bll/share.php';
$act = isset($_REQUEST["act"]) ? $_REQUEST["act"] : "list";
if ($act == "list") {
    $smarty->display('admin/admin_data_list.html');
} elseif ($act == "getlist") {
    $page = isset($_REQUEST["page"]) ? intval($_REQUEST["page"]) : 1;
    $page_size = isset($_REQUEST["page_size"]) ? intval($_REQUEST["page_size"]) : 25;
    $type = isset($_REQUEST["type"]) ? intval($_REQUEST["type"]) : 0;
    $dataclass_id = isset($_REQUEST["dataclass_id"]) ? intval($_REQUEST["dataclass_id"]) : 0;
    $wq = "type = " . $type;
    $wq_list = "d.type = " . $type;
    if ($dataclass_id) {
        get_children_id($dataclass_id);
        $children_id = implode(",", $children_id);
        $wq .= " and dataclass_id in(" . $children_id . ")";
        $wq_list .= " and d.dataclass_id in(" . $children_id . ")";
    }
    $sql = SqlText::func("count", "id", "data", $wq);
    $total = $db->get_var($sql);
    $page_count = page_count($total, $page_size);
    $sql = "select d.* , dc.id as dc_id , dc.name as dc_name from data as d inner join dataclass as dc on d.dataclass_id = dc.id where " . $wq_list . " order by d.sort desc , d.id desc limit " . ($page - 1) * $page_size . " , " . $page_size;
    $list = $db->get_results($sql, ARRAY_A);
    foreach ($list as &$v) {
        $v["add_time"] = date("Y-m-d H:i:s", $v["add_time"]);
    }
    output_json(0, "请求成功", array("total" => $total, "page" => $page, "page_count" => $page_count, "list" => $list));
} elseif ($act == "add") {
    $id = isset($_REQUEST["id"]) ? intval($_REQUEST["id"]) : 0;