


PHP implementation framework of online bidding system (1)_PHP tutorial
Earlier, I gave a class for paging mysql records, but did not give an example of its use. Now, I have compiled an online bidding system framework program I just wrote to illustrate the use of this class, and it is also for online bidding. Let’s discuss the implementation method with everyone.
First of all, let me state that I am not a master or an expert, I am just a fan, so this program must have many loopholes, but the reason why I dare to bring it out is because I really hope to freely share PHP with everyone. Bring us happiness. (Actually, I want to add more points to get a space that supports mysql^_^)
I think there are two biggest differences between the auction system and the general supply and demand information release system. One is The new price offered by the bidder must be reflected in the price of the product in a timely manner. Another point is that there is a time limit. After the bidding ends, bidding must stop. And the final winning bidder will be announced.
I haven’t thought of the others yet, maybe an expert can give me some introduction.
Therefore, I think it should not be difficult to turn a supply and demand information release system into an auction system.
Let’s first show the new version of TViewPage class and database structure.
<?php
/*********************************************
TViewPage v 1.2
Class for paging display of Mysql database records
Author: sharetop
E-mail:ycshowtop@21cn.com
Time: 2000-8-31
[ 2000-9-6] 1.2
Fixed a bug in readlist() and put the verification offset into the class.
Add three basic operation functions add() delete() modify().
This class does not provide the function of connecting to the database, so the corresponding database needs to be opened externally.
This class does not provide the function of displaying records. It only reads records into the Result two-dimensional array in pages.
The data display format needs to be customized externally.
***********************************************/
class TViewPage {
var $Table; //Table name
var $MaxLine; //Every Number of rows displayed on the page
var $Offset; //Record offset
var $Total; //Total number of records
var $Number; //Number of records read on this page
var $Result; //Read results
var $TPages; //Total number of pages
var $CPages; //Current number of pages
var $Condition; //Display Conditions such as: where id='$id' order by id desc
var $PageQuery; //Page display parameters to be passed
//******Constructor***** ********
//Parameters: table name, maximum number of rows, offset
function TViewPage($TB,$ML){
global $offset;
$this->Table=$TB;
$this->MaxLine=$ML;
if(isset($offset)) $this->Offset=$offset;
else $this->Offset=0;
$this->Condition="";
}
//********Set display conditions *********
//For example: where id='$id' order by id desc
//The requirement is a string, conforming to SQL syntax (this string will be added after the SQL statement )
function SetCondition($s){
$this->Condition=$s;
}
//******Set the passing parameters** **********
// key parameter name value parameter value
// For example: setpagequery("id",$id); If there are multiple parameters to be passed, it can be called multiple times This function.
function SetPageQuery($key,$value){
$tmp[key]=$key; $tmp[value]=$value;
$this->PageQuery[]=$ tmp;
}
//********Read record****************
//Main working function, according to The given conditions read the corresponding records from the table
// The return value is a two-dimensional array, Result[record number][field name]
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) { //according to ConditionCondition
$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;
}
//************Add new record**********
//$str is the added value, such as "'$id','$name','$class'", etc.
function Add($str){
$SQL=" INSERT INTO ".$this->Table." VALUES(".$str.")";
mysql_query($SQL) or die(mysql_error());
}
//**********Delete record************
//First call SetCondition() to determine the conditions.
function Delete(){
$SQL="DELETE FROM ".$this->Table." ".$this->Condition;
mysql_query($SQL) or die( mysql_error());
}
//************Modify record************
//$field field name$value New value
//If you want to modify multiple fields, you can call the function repeatedly.
function Modify($field,$value){
$SQL="UPDATE FROM ".$this->Table." SET ".$field."=".$value." " .$this->Condition;
mysql_query($SQL) or die(mysql_error());
}
//**********Display Page count**********
//Display the current page and total page count
function ThePage() {
$this->TPages=ceil( $this->Total/$this->MaxLine);
$this->CPages=$this->Offset/$this->MaxLine+1;
echo "th".$ this->CPages."Pages/Total".$this->TPages."Pages";
}
//************Display page button* ************
//This function should be called after the ThePage() function! ! !
//Display the homepage, next page, previous page, and next page, and add the parameters to be passed
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=""; //Generate a parameter string to pass
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.">Homepage>|";
if($prev>=0)
echo "<A href=$PHP_SELF?offset=".$prev.$strQuery." >Previous page</A>|";
if($next<$this->Total)
echo "<A href=$PHP_SELF?offset=".$next.$strQuery." >Next page</A>|";
if($this->TPages!=0 && $this->CPages<$this->TPages)
echo "<A href= $PHP_SELF?offset=".$last.$strQuery.">Last page</A>";
}
//******end class
}
?>
//************************
ebid.sql file ( I exported it using phpmyadmin)
# phpMyAdmin MySQL-Dump
# http://www.htmlwizard.net/phpMyAdmin/
#
# Host: localhost Database: ebid
#------------------------------------------------ -----------
# Table structure for table 'reply'
# id, product id, bidder, bidder's email, bid.
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, product name, introduction, original price, markup unit, end time, number of bids, current price, whether there are photos
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)
);
The configuration file is as follows:
//**************
//config.inc.php
<?php
$HOST="localhost"; //Host name
$DATABASE="ebid"; //Database name
$WARE_TABLE="shop"; //Product table
$BID_TABLE="reply"; //Response table
$USER="root"; //User
$PASSWD="9999"; //Password
$PAGE_MAX_LINE=20; //Number of lines displayed per page
//Open the database
$LinkID=mysql_connect($HOST,$USER,$PASSWD);
mysql_select_db($DATABASE,$LinkID) or die(mysql_error());
?>
The following is the function to display products and TOP10 products
//**********************
//
< ?php
include "config.inc.php";
include "tview.class.php"; //Class file
//*****Display product list* *******
function PrintList(){
global $view;
$ct=time();
//Sentence to set conditions! It must meet the SQL syntax. Only display products that have not ended bidding
$view->SetCondition("where endtime>'$ct' order by id desc");
//Call member function to read records
/ /Result$result[record number][field name] is a two-dimensional array.
$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>

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.
