前面我给了一个分页显示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>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools