Home Backend Development PHP Tutorial 在线竞拍系统的PHP实现框架(一)_PHP

在线竞拍系统的PHP实现框架(一)_PHP

Jun 01, 2016 pm 12:27 PM
id online accomplish frame system

前面我给了一个分页显示mysql记录的类,却没给出使用的例子,现在,我整理了我刚写的一个在线竞拍系统框架程序,来说明这个类的使用方法,而且也就在线竞拍的实现方法与大家一起来讨论一下。

  首先声明,我不是高手,也不是行家,只是一个fans,所以这个程序肯定有不少漏洞,但我之所以敢拿出来,是因为我很希望能自由地与大家分享PHP带给我们的快乐。(其实是想多加点分好弄个支持mysql的空间^_^)


  我觉得竞拍系统与一般的供求信息发布系统相比,最大的不同有两点,一点是出价者开的新价要及时地反映在商品的价格上,另一点是有时间的限制,在竞标结束后,就要停止出价。并且给出最后中标者。

  其它的我还没想到呢,有行家给点介绍吧。

  所以,我想把一个供求信息发布系统做成一个竞拍系统应是不困难的事吧。

下面先把新版的TViewPage类和数据库结构给出来吧。

<?php
/*********************************************
TViewPage v 1.2

分页显示Mysql数据库记录的类

作者:sharetop
E-mail:ycshowtop@21cn.com
时间:2000-8-31

[2000-9-6] 1.2
修正了readlist()的一个bug,将验证offset放入类中。
增加add() delete() modify()三个基本操作函数。

  本类没有提供连接数据库的功能,所以需在外部打开相应的数据库。
  本类也没有提供显示记录的功能,只是分页读取记录至 Result二维数组中。
  需在外部自定义数据显示格式。
***********************************************/
class TViewPage {

var $Table; //表名
var $MaxLine; //每页显示行数

var $Offset; //记录偏移量
var $Total; //记录总数
var $Number; //本页读取的记录数
var $Result; //读出的结果

var $TPages; //总页数
var $CPages; //当前页数

var $Condition; //显示条件 如:where id='$id' order by id desc
var $PageQuery; //分页显示要传递的参数

//******构造函数*************
//参数:表名、最大行数、偏移量

function TViewPage($TB,$ML){
global $offset;

$this->Table=$TB;
$this->MaxLine=$ML;
if(isset($offset)) $this->Offset=$offset;
else $this->Offset=0;
$this->Condition="";
}


//********设置显示条件*********
//如:where id='$id' order by id desc
//要求是字串,符合SQL语法(本字串将加在SQL语句后)

function SetCondition($s){
$this->Condition=$s;
}

//******设置传递参数************
// key参数名 value参数值
// 如:setpagequery("id",$id);如有多个参数要传递,可多次调用本函数。

function SetPageQuery($key,$value){
$tmp[key]=$key; $tmp[value]=$value;
$this->PageQuery[]=$tmp;
}

//********读取记录***************
// 主要工作函数,根据所给的条件从表中读取相应的记录
// 返回值是一个二维数组,Result[记录号][字段名]

function ReadList() {
$SQL="SELECT Count(*) AS total FROM ".$this->Table." ".$this->Condition;

$result=mysql_query($SQL) or die(mysql_error());
$row=mysql_fetch_Array($result);
$this->Total=$row[total];

if($this->Total>0) { //根据条件 Condition
$SQL="SELECT * FROM ".$this->Table." ".$this->Condition.
" LIMIT ".$this->Offset." , ".$this->MaxLine;

$result=mysql_query($SQL) or die(mysql_error());
$this->Number=mysql_num_rows($result);

$i=0;
while($row=mysql_fetch_Array($result)){
$this->Result[$i]=$row;
$i ;
}
}
return $this->Result;
}


//*******加入新记录**********
//$str为加入的值,如 "'$id','$name','$class'"等

function Add($str){

$SQL="INSERT INTO ".$this->Table." VALUES(".$str.")";
mysql_query($SQL) or die(mysql_error());

}

//*********删除记录**********
//先调用SetCondition()来确定条件。

function Delete(){
$SQL="DELETE FROM ".$this->Table." ".$this->Condition;
mysql_query($SQL) or die(mysql_error());
}

//********修改记录************
//$field 字段名 $value新值
//如要修改多个字段可重复调用来函数。

function Modify($field,$value){
$SQL="UPDATE FROM ".$this->Table." SET ".$field."=".$value." ".$this->Condition;
mysql_query($SQL) or die(mysql_error());
}


//**********显示页数*************
//显示当前页及总页数

function ThePage() {
$this->TPages=ceil($this->Total/$this->MaxLine);
$this->CPages=$this->Offset/$this->MaxLine 1;
echo "第".$this->CPages."页/共".$this->TPages."页";
}

//**********显示翻页按钮*************
//此函数要在ThePage()函数之后调用!!!
//显示首页、下页、上页、未页,并加上要传递的参数

function Page() {
$first=0;
$next=$this->Offset $this->MaxLine;
$prev=$this->Offset-$this->MaxLine;
$last=($this->TPages-1)*$this->MaxLine;

$k=count($this->PageQuery);
$strQuery=""; //生成一个要传递参数字串
for($i=0;$i<$k;$i ){
$strQuery.="&".$this->PageQuery[$i][key]."=".$this->PageQuery[$i][value];
}

if($this->Offset>=$this->MaxLine)
echo "<A href=$PHP_SELF?offset=".$first.$strQuery.">首页</A>|";
if($prev>=0)
echo "<A href=$PHP_SELF?offset=".$prev.$strQuery.">上一页</A>|";
if($next<$this->Total)
echo "<A href=$PHP_SELF?offset=".$next.$strQuery.">下一页</A>|";
if($this->TPages!=0 && $this->CPages<$this->TPages)
echo "<A href=$PHP_SELF?offset=".$last.$strQuery.">末页</A>";
}

//******end class
}

?>


//************************
ebid.sql文件(我是用phpmyadmin导出的)

# phpMyAdmin MySQL-Dump
# http://www.htmlwizard.net/phpMyAdmin/
#
# Host: localhost Database : ebid

# --------------------------------------------------------
# Table structure for table 'reply'
# id,商品id,出价人,出价人的email,出价。

CREATE TABLE reply (
id varchar(16) NOT NULL,
parentid varchar(16) NOT NULL,
buyer varchar(12) NOT NULL,
email varchar(32) NOT NULL,
price float(10,2) DEFAULT '0.00' NOT NULL,
PRIMARY KEY (id, price)
);


# --------------------------------------------------------
# Table structure for table 'shop'
# id,商品名,介绍,原始价,加价单位,结束时间,竞标数,当前价,是否有照片

CREATE TABLE shop (
id varchar(16) NOT NULL,
name varchar(50) NOT NULL,
description text,
price float(10,2) DEFAULT '0.00' NOT NULL,
unit tinyint(2) unsigned NOT NULL,
endtime varchar(16) DEFAULT '0000-00-00 00:00' NOT NULL,
reply int(4) unsigned NOT NULL,
curprice float(10,2) DEFAULT '0.00' NOT NULL,
photo tinyint(1) unsigned NOT NULL,
PRIMARY KEY (id),
KEY kreply (reply)
);


配置文件如下:
//**************
//config.inc.php

<?php

$HOST="localhost"; //主机名
$DATABASE="ebid"; //数据库名
$WARE_TABLE="shop"; //商品表
$BID_TABLE="reply"; //回应表
$USER="root"; //用户
$PASSWD="9999"; //密码

$PAGE_MAX_LINE=20; //每页显示行数

//打开数据库
$LinkID=mysql_connect($HOST,$USER,$PASSWD);
mysql_select_db($DATABASE,$LinkID) or die(mysql_error());

?>

以下是显示商品及TOP10商品的函数
//*****************
//
<?php
include "config.inc.php";
include "tview.class.php"; //类文件


//*****显示商品列表********
function PrintList(){
global $view;

$ct=time();

//设置条件的句子!要满足SQL语法哦。只显示没有结束竞标的商品
$view->SetCondition("where endtime>'$ct' order by id desc");

//调用成员函数来读记录
//结果$result[记录号][字段名] 是二维数组。
$result=$view->ReadList();

if($view->Number==0) {echo "<tr><td colspan=4> </td></tr>"; return;}

for($i=0;$i<$view->Number;$i ){
if(ceil($i/2)*2==$i) $bgc="#ffffff";
else $bgc="#f3f3f3";
echo "<tr bgcolor=$bgc><td width=60% >";
echo "<a href="javascript:showdetail('detail.php?id=".$result[$i][id]."')">".$result[$i][name]."</a>";
echo "</td><td width=15% >";
echo date("Y-m-j 24:00:00",$result[$i][endtime]);
echo "</td><td width=15% align=right>¥";
echo $result[$i][curprice];
echo "</td><td width=10% align=right>";
echo $result[$i][reply];
echo "</td></tr>";
}
}

//*********显示最热的10条记录**********
function ListTopHot(){
global $view;

//同样先设置条件
$view->SetCondition("order by reply desc");
//读记录
$result=$view->ReadList();

$k=(count($result)>10)? '10':(count($result));

for($i=0;$i<$k;$i ){
echo "<tr><td>";
echo "<a href="javascript:showdetail('detail.php?id=".$result[$i][id]."')">".$result[$i][name]."</a>";
echo "</td></tr>";
}

}


//*********显示最新10条记录***********
function ListTopNew(){
global $view;

$view->SetCondition("order by id desc");
$result=$view->ReadList();

$k=(count($result)>10)? '10':(count($result));

for($i=0;$i<$k;$i ){
echo "<tr><td>";
echo "<a href="javascript:showdetail('detail.php?id=".$result[$i][id]."')">".$result[$i][name]."</a>";
echo "</td></tr>";
}
}


//********** //构造这个viewpage类,给出商品表及每页显示行数

$view=new TViewPage($WARE_TABLE,$PAGE_MAX_LINE);

?>

下面给出用到的一个js函数吧,很简单,就是打开一个新窗口:
<script>
function showdetail(str){
window.open(str,"newwin","top=20,left=20,width=600,height=400,
location=no,toolbar=no,status=no,resizable=no,scrollbars=yes");
}
</script>

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

How to evaluate the cost-effectiveness of commercial support for Java frameworks How to evaluate the cost-effectiveness of commercial support for Java frameworks Jun 05, 2024 pm 05:25 PM

Evaluating the cost/performance of commercial support for a Java framework involves the following steps: Determine the required level of assurance and service level agreement (SLA) guarantees. The experience and expertise of the research support team. Consider additional services such as upgrades, troubleshooting, and performance optimization. Weigh business support costs against risk mitigation and increased efficiency.

Huawei will launch the Xuanji sensing system in the field of smart wearables, which can assess the user's emotional state based on heart rate Huawei will launch the Xuanji sensing system in the field of smart wearables, which can assess the user's emotional state based on heart rate Aug 29, 2024 pm 03:30 PM

Recently, Huawei announced that it will launch a new smart wearable product equipped with Xuanji sensing system in September, which is expected to be Huawei's latest smart watch. This new product will integrate advanced emotional health monitoring functions. The Xuanji Perception System provides users with a comprehensive health assessment with its six characteristics - accuracy, comprehensiveness, speed, flexibility, openness and scalability. The system uses a super-sensing module and optimizes the multi-channel optical path architecture technology, which greatly improves the monitoring accuracy of basic indicators such as heart rate, blood oxygen and respiration rate. In addition, the Xuanji Sensing System has also expanded the research on emotional states based on heart rate data. It is not limited to physiological indicators, but can also evaluate the user's emotional state and stress level. It supports the monitoring of more than 60 sports health indicators, covering cardiovascular, respiratory, neurological, endocrine,

How do the lightweight options of PHP frameworks affect application performance? How do the lightweight options of PHP frameworks affect application performance? Jun 06, 2024 am 10:53 AM

The lightweight PHP framework improves application performance through small size and low resource consumption. Its features include: small size, fast startup, low memory usage, improved response speed and throughput, and reduced resource consumption. Practical case: SlimFramework creates REST API, only 500KB, high responsiveness and high throughput

How to choose the best golang framework for different application scenarios How to choose the best golang framework for different application scenarios Jun 05, 2024 pm 04:05 PM

Choose the best Go framework based on application scenarios: consider application type, language features, performance requirements, and ecosystem. Common Go frameworks: Gin (Web application), Echo (Web service), Fiber (high throughput), gorm (ORM), fasthttp (speed). Practical case: building REST API (Fiber) and interacting with the database (gorm). Choose a framework: choose fasthttp for key performance, Gin/Echo for flexible web applications, and gorm for database interaction.

Xiaomi restricts national bank devices from using the international version of the system! Unable to enter the system after flashing Xiaomi restricts national bank devices from using the international version of the system! Unable to enter the system after flashing Jul 12, 2024 am 10:23 AM

According to news on July 9, testers of Xiaomi.EU, a well-known official version of the system, recently discovered that Xiaomi has recently taken new measures to restrict devices sold in mainland China from installing the Xiaomi international version. If a user attempts to install the international version of the system on a Chinese version of the device, the device will display an unsupported message during boot and will be unable to enter the system. This mechanism can identify the market version to which the hardware belongs. For Xiaomi mobile phones sold in mainland China, if it is detected that the international version of the system is installed, it will not be able to start normally. Test results show that the flashed device will display "Unsupported software" (unsupported software) in the boot wizard and prompt that using this version may bring security risks. Currently, Xiaomi has

How does the learning curve of PHP frameworks compare to other language frameworks? How does the learning curve of PHP frameworks compare to other language frameworks? Jun 06, 2024 pm 12:41 PM

The learning curve of a PHP framework depends on language proficiency, framework complexity, documentation quality, and community support. The learning curve of PHP frameworks is higher when compared to Python frameworks and lower when compared to Ruby frameworks. Compared to Java frameworks, PHP frameworks have a moderate learning curve but a shorter time to get started.

See all articles