search
HomeBackend DevelopmentPHP TutorialPHP implementation framework of online bidding system (1)_PHP tutorial

PHP implementation framework of online bidding system (1)_PHP tutorial

Jul 21, 2016 pm 04:10 PM
mysqlphponePaginationonlineaccomplishIshowframeofkindsystemRecord

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>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/314261.htmlTechArticle前面我给了一个分页显示mysql记录的类,却没给出使用的例子,现在,我整理了我刚写的一个在线竞拍系统框架程序,来说明这个类的使用方...
Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

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: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

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 and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

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 and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

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.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

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 and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

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.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

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

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

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.

See all articles

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

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.