/**
 * 
 * @param string $where
 * @return array 返回数据库查询后的数组:
 */
function pagination($where, $conn, $tbl_name)
{
    require_once 'class/Config_commodity.php';
    require_once 'class/DBpagination.php';
    require_once 'class/DBcount.php';
    require_once 'class/Info_user.php';
    require_once 'class/Config_user.php';
    require_once 'Include_picture.php';
    //2.向数据库查询符合条件数,以计算显示分页数目
    $dbcount = new DBcount($tbl_name, $where);
    $retval = $dbcount->excute($conn);
    $row = mysqli_fetch_array($retval, MYSQLI_NUM);
    $count = 1 + (int) (($row ? $row[0] : 0) / SIZE_EACH_PAGE);
    //3.计算当前页码;
    $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
    $page = $page > $count ? $count : $page;
    //4. 查询当前页的数据
    $choosed_fields = array(Config_commodity::table_name . '.' . Config_commodity::description, Config_commodity::table_name . '.' . Config_commodity::id, Config_commodity::table_name . '.' . Config_commodity::publisher, Config_commodity::table_name . '.' . Config_commodity::title, Config_commodity::table_name . '.' . Config_commodity::price, Config_commodity::table_name . '.' . Config_commodity::release_date, Config_commodity::table_name . '.' . Config_commodity::praise, Config_commodity::table_name . '.' . Config_commodity::leave_message_time, Config_commodity::table_name . '.' . Config_commodity::id);
    $DBpagination = new DBpagination($tbl_name, $where, $page, SIZE_EACH_PAGE, $choosed_fields);
    $reval = $DBpagination->excute($conn);
    //逐个配置 array 三级关联数组  供界面使用
    $array = array();
    while (($temp_database_row_array = mysqli_fetch_array($reval, MYSQLI_ASSOC)) != null) {
        $userinfo = Info_user::get_user_info_by_id($conn, $temp_database_row_array[Config_commodity::publisher]);
        $array[] = array('imgs' => get_commodity_pic($conn, $temp_database_row_array[Config_commodity::id]), 'description' => $temp_database_row_array[Config_commodity::description], 'title' => $temp_database_row_array[Config_commodity::title], 'price' => $temp_database_row_array[Config_commodity::price], 'url' => 'upload/default.jpg', 'name' => $userinfo[Config_user::log_name], 'time' => get_time($temp_database_row_array[Config_commodity::release_date]), 'star_numbers' => $temp_database_row_array[Config_commodity::praise], 'message_numbers' => $temp_database_row_array[Config_commodity::leave_message_time], 'id' => $temp_database_row_array[Config_commodity::id]);
    }
    //5.释放资源
    mysqli_free_result($reval);
    return array('page' => $page, 'array' => $array);
}
Example #2
0
/**
 * 
 * @param integer $commodity_id
 * @param integer $praiser_id
 * @return boolean 返回是否已经存在对应的记录
 */
function is_praised($conn, $commodity_id, $praiser_id)
{
    require_once 'class/DBcount.php';
    require_once 'class/Config_praise.php';
    $DBcount = new DBcount(Config_praise::tbl_name, 'where ' . Config_praise::commodity_id . ' = ' . "'" . $commodity_id . "'" . ' AND ' . Config_praise::praiser_id . ' = ' . "'" . $praiser_id . "'");
    $retval = $DBcount->excute($conn);
    $row = mysqli_fetch_array($retval, MYSQLI_NUM);
    return $row ? $row[0] : 0;
}
Example #3
0
/**
 * 
 * @param string $username
 */
function is_username_exist($username)
{
    include_once 'class/DBtraverser.php';
    include_once 'class/Config.php';
    include_once 'class/Config_user.php';
    include_once 'class/DBcount.php';
    $ary = ' where ' . Config_user::log_name . " = '{$username}' ";
    $myDBcount = new DBcount(Config_user::table_name, $ary);
    return $myDBcount->excute_without_conn();
}
Example #4
0
/**
 *
 * @param string $username
 */
function is_username_exist($username)
{
    include_once 'class/DBtraverser.php';
    include_once 'class/Config.php';
    include_once 'class/Config_user.php';
    include_once 'class/DBcount.php';
    $ary = ' where ' . Config_user::log_name . " = '{$username}' ";
    $myDBcount = new DBcount(Config_user::table_name, $ary);
    $retval = $myDBcount->excute_without_conn();
    $row = mysqli_fetch_array($retval, MYSQLI_NUM);
    return $row ? $row[0] : 0;
}
function transaction($course_and_reward, $user_id, $page)
{
    require_once 'class/Config_transaction.php';
    require_once 'class/Config_commodity.php';
    require_once 'class/commodity/Commodity_type_Config.php';
    require_once 'class/Config.php';
    //0.where
    if ($course_and_reward == Commodity_type_Config::all) {
        $where = ' where ' . Config_transaction::table_name . "." . Config_transaction::commodity_buyer_id . '=' . "'" . $user_id . "'" . ' OR ' . Config_transaction::table_name . "." . Config_transaction::commodity_holder_id . '=' . "'" . $user_id . "'";
    } else {
        if ($course_and_reward == Commodity_type_Config::course) {
            $where = ' where ' . Config_transaction::table_name . "." . Config_transaction::commodity_buyer_id . '=' . "'" . $user_id . "'";
        } else {
            $where = ' where ' . Config_transaction::table_name . "." . Config_transaction::commodity_holder_id . '=' . "'" . $user_id . "'";
        }
    }
    //    $where = 'select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id       ';
    //1.连接数据库
    $conn = Config::connect();
    //多次使用的数据库连接
    //2.向数据库查询符合条件数,以计算显示分页数目
    $dbcount = new DBcount(Config_transaction::table_name, $where);
    $count = 1 + (int) ($dbcount->excute($conn) / SIZE_EACH_PAGE);
    //3.计算当前页码;
    $page = $page < 1 ? 1 : (int) $page;
    $page = $page > $count ? $count : $page;
    //4.分页执行
    $query = 'select ' . Config_transaction::table_name . "." . Config_commodity::commodity_state . ',' . Config_commodity::table_name . "." . Config_commodity::pic_path . ',' . Config_commodity::table_name . "." . Config_commodity::course_or_reward . ',' . Config_commodity::table_name . "." . Config_commodity::description . ',' . Config_commodity::table_name . "." . Config_commodity::id . ',' . Config_commodity::table_name . "." . Config_commodity::type . ' from ' . Config_transaction::table_name . ',' . Config_commodity::table_name . ' ' . $where . ' AND ' . Config_commodity::table_name . '.' . Config_commodity::id . '=' . Config_transaction::table_name . '.' . Config_transaction::choosed_id . ' DESC LIMIT ' . ($page - 1) * SIZE_EACH_PAGE . ',' . SIZE_EACH_PAGE;
    $retval = mysqli_query($conn, $query);
    $array = array();
    while (($temp_database_row_array = mysqli_fetch_array($retval, MYSQLI_ASSOC)) != null) {
        //array_push($array, $temp_database_row_array);
        //据说以下类似方法效率高一倍
        $array[] = $temp_database_row_array;
    }
    mysqli_close($conn);
    mysqli_free_result($retval);
}
Example #6
0
 require_once 'class/Config_commodity.php';
 require_once 'class/DBcount.php';
 require_once 'class/Config_user.php';
 require_once 'class/commodity/Commodity_type_Config.php';
 $conn = Config::connect();
 $id = $_SESSION['CURRENT_LOGIN_ID'];
 //choose from user table
 $income_and_pay = Info_user::get_user_account($conn, $id);
 $username_avatar = Info_user::get_user_avatar_and_logname($conn, $id);
 $income_and_outcome = array('income' => $income_and_pay[Config_user::income], 'outcome' => $income_and_pay[Config_user::pay], 'url_header' => 'upload/avatar.png', 'username' => $username_avatar[Config_user::log_name]);
 //choose from
 $tbl_name = Config_budget::table_name . ',' . Config_commodity::table_name;
 $choose_fields = array(Config_budget::table_name . '.' . Config_budget::holder_id, Config_budget::table_name . '.' . Config_budget::payer_id, Config_budget::table_name . '.' . Config_budget::pay_date, Config_commodity::table_name . '.' . Config_commodity::price, Config_commodity::table_name . '.' . Config_commodity::title, Config_commodity::table_name . '.' . Config_commodity::id, Config_commodity::table_name . '.' . Config_commodity::publisher, Config_commodity::table_name . '.' . Config_commodity::course_or_reward);
 $where = ' where ' . Config_budget::table_name . '.' . Config_budget::commodity_id . ' = ' . Config_commodity::table_name . '.' . Config_commodity::id . ' AND (' . Config_budget::table_name . '.' . Config_budget::holder_id . ' = ' . "'{$id}'" . ' OR ' . Config_budget::table_name . '.' . Config_budget::payer_id . ' = ' . "'{$id}'" . ')';
 //向数据库查询符合条件数,以计算显示分页数目
 $dbcount = new DBcount($tbl_name, $where);
 $retval = $dbcount->excute($conn);
 $row = mysqli_fetch_array($retval, MYSQLI_NUM);
 $count = 1 + (int) (($row ? $row[0] : 0) / SIZE_EACH_PAGE);
 //3.计算当前页码;
 $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
 $page = $page > $count ? $count : $page;
 $DBpagination = new DBpagination($tbl_name, $where, $page, SIZE_EACH_PAGE, $choose_fields);
 $retval = $DBpagination->excute($conn);
 $account_ary = array();
 while (($temp_account_ary = mysqli_fetch_array($retval, MYSQLI_ASSOC)) != null) {
     $is_loginer_income = $temp_account_ary[Config_budget::holder_id] == $id;
     if ($is_loginer_income) {
         $trader = $temp_account_ary[Config_budget::payer_id];
     } else {
         $trader = $temp_account_ary[Config_budget::holder_id];
 require_once 'class/Config_transaction.php';
 require_once 'class/Config_commodity.php';
 require_once 'class/commodity/Commodity_type_Config.php';
 require_once 'class/Config.php';
 //0.where
 if ((int) $_GET['course_and_reward'] == Commodity_type_Config::course) {
     $where = 'where ' . Config_transaction::table_name . "." . Config_transaction::commodity_buyer_id . '=' . "'" . $_SESSION['CURRENT_LOGIN_ID'] . "'";
 } else {
     $where = 'where ' . Config_transaction::table_name . "." . Config_transaction::commodity_holder_id . '=' . "'" . $_SESSION['CURRENT_LOGIN_ID'] . "'";
 }
 //    $where = 'select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id       ';
 //1.连接数据库
 $conn = Config::connect();
 //多次使用的数据库连接
 //2.向数据库查询符合条件数,以计算显示分页数目
 $dbcount = new DBcount(Config_transaction::table_name, $where);
 $count = 1 + (int) ($dbcount->excute($conn) / SIZE_EACH_PAGE);
 //3.计算当前页码;
 $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
 $page = $page > $count ? $count : $page;
 //4.分页执行
 $query = 'select ' . Config_transaction::table_name . "." . Config_commodity::commodity_state . ',' . Config_commodity::table_name . "." . Config_commodity::pic_path . ',' . Config_commodity::table_name . "." . Config_commodity::course_or_reward . ',' . Config_commodity::table_name . "." . Config_commodity::description . ',' . Config_commodity::table_name . "." . Config_commodity::id . ',' . Config_commodity::table_name . "." . Config_commodity::type . ',' . Config_transaction::table_name . "." . Config_transaction::commodity_buyer_id . ',' . Config_transaction::table_name . "." . Config_transaction::commodity_holder_id . ' from ' . Config_transaction::table_name . ',' . Config_commodity::table_name . ' ' . $where . ' AND ' . Config_commodity::table_name . '.' . Config_commodity::id . '=' . Config_transaction::table_name . '.' . Config_transaction::choosed_id . ' DESC LIMIT ' . ($page - 1) * SIZE_EACH_PAGE . ',' . SIZE_EACH_PAGE;
 $retval = mysqli_query($conn, $query);
 $array_commofity_info = array();
 while (($temp_database_row_array = mysqli_fetch_array($retval, MYSQLI_ASSOC)) != null) {
     //array_push($array, $temp_database_row_array);
     //据说以下类似方法效率高一倍
     $array_commofity_info[] = $temp_database_row_array;
 }
 mysqli_close($conn);
 mysqli_free_result($retval);