PHP implementation framework of Online Bidding System (I)

Source: Internet
Author: User
Tags echo date

I previously gave a class for displaying MySQL records by page, but did not give examples. Now, I have sorted out a framework of an online bidding system I just wrote. Program To describe how to use this class, and discuss the implementation method of online bidding.

First, I declare that I am neither a master nor an expert, but a fans. Therefore, this program must have many vulnerabilities, but I dare to come up with them, it is because I want to share with you the joy PHP brings. (In fact, I want to add more points to get a space that supports MySQL ^_^)

I think there are two biggest differences between the bidding system and the general supply and demand information publishing system. One point is that the new prices offered by the market users should be promptly reflected in the prices of goods, another point is that there is a time limit. After the bidding ends, the bid will be stopped. And the final winner is given.

I haven't thought of anything else yet. Some experts will give me some introductions.

Therefore, it is not difficult for me to make a bidding system based on supply and demand information.

Next, let's give the new tviewpage class and database structure.

<? PHP
/*************************************** ******
Tviewpage v1.2

Categories of MySQL database records displayed on pages

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 () Delete () Modify () three basic operation functions.

This class does not provide the function of connecting to the database, so you need to open the corresponding database outside.
This category does not provide the display record function, but only reads records to the result two-dimensional array by page.
You must customize the data display format.
**************************************** *******/
Class tviewpage {

VaR $ table; // table name
VaR $ maxline; // number of lines per page

VaR $ offset; // record offset
VaR $ total; // The total number of records.
VaR $ number; // number of records read on the current page
VaR $ result; // read the result

VaR $ tpages; // the total number of pages.
VaR $ cpages; // current page number

VaR $ condition; // display conditions such as: Where id = '$ id' order by ID DESC
VaR $ pagequery; // display the parameters to be passed by PAGE

// ******* Constructor *************
// Parameter: Table Name, maximum number of rows, and 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
// It must be a string that complies with the SQL syntax (this string will be added after the SQL statement)

Function setcondition ($ s ){
$ This-> condition = $ S;
}

// ******* Set the passing parameter ************
// Key parameter name value
// For example, setpagequery ("ID", $ id). You can call this function multiple times if multiple parameters are to be passed.

Function setpagequery ($ key, $ value ){
$ TMP [Key] = $ key; $ TMP [value] = $ value;
$ This-> pagequery [] = $ TMP;
}

***************
// Main working function, which reads the corresponding records from the table based on the given conditions
// The returned 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) {// 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;
}

// ******* Add a new record **********
// $ STR indicates the added value, such as '$ id',' $ name', and '$ class'.

Function add ($ Str ){

$ SQL = "insert into". $ this-> table. "values (". $ Str .")";
Mysql_query ($ SQL) or die (mysql_error ());

}

// *********** Delete a record **********
// Call setcondition () to determine the condition.

Function Delete (){
$ SQL = "delete from". $ this-> table. "". $ this-> condition;
Mysql_query ($ SQL) or die (mysql_error ());
}

// ********* Modify the record ************
// $ Field name $ value New Value
// 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 number *************
// Display the current page and the total number of pages

Function thepage (){
$ This-> tpages = Ceil ($ this-> total/$ this-> maxline );
$ This-> cpages = $ this-> offset/$ this-> maxline + 1;
Echo "no.". $ this-> cpages. "Page/total". $ this-> tpages. "Page ";
}

// *********** Display the flip button *************
// This function must be called after the thepage () function !!!
// Display the home page, next page, last page, and unpage, 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 be passed
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 </a> | ";
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, item ID, bidder, bidder's email, and 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, description, original price, markup unit, end time, number of bids, current price, and photo

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 '2017-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"; // item table
$ Bid_table = "reply"; // Response Table
$ User = "root"; // user
$ Passwd = "9999"; // Password

$ Page_max_line = 20; // number of lines per page

// Open the database
$ Linkid = mysql_connect ($ host, $ user, $ passwd );
Mysql_select_db ($ database, $ linkid) or die (mysql_error ());

?>

The following are functions for displaying products and top 10 products:
//*****************
//
<? PHP
Include "config. Inc. php ";
Include "tview. Class. php"; // class file

// ***** Display the product list ********
Function printlist (){
Global $ view;

$ Ct = Time ();

// Set the condition sentence! The SQL syntax must be satisfied. Only products that have not ended the bidding are displayed
$ View-> setcondition ("where endtime> '$ CT' order by id desc ");

// Call the 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> ";
}
}

// ********** Display the top 10 records **********
Function listtophot (){
Global $ view;

// Set conditions first
$ View-> setcondition ("order by reply DESC ");
// Read records
$ 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> ";
}

}

// ********** Display the latest 10 records ***********
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> ";
}
}

// ********** <End Function Definition, main program body *************
// Construct this viewpage class and provide the product table and the number of lines displayed on each page

$ View = new tviewpage ($ ware_table, $ page_max_line );

?>

The following shows a JS function. It is very simple to open a new window:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.