PHP implementation framework of online bidding system

Source: Internet
Author: User
I previously gave a class for displaying mysql records by page, but did not give an example for use. now, I have sorted out a framework program of the online bidding system I just wrote, this section describes how to use this class, and discusses the implementation of online bidding. First, I declare that I am neither a master nor an expert, but a fans, so this program certainly has many classes that I have previously provided for displaying mysql records on pages, but I have not provided examples for use, now, I have compiled a Framework Program of the online bidding system that I just wrote to describe how to use this class, and I will discuss the implementation method of online bidding with you.

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

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> ";
}
}


//********** <结束函数定义,主程序体************* < b>
// 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 is a js function, which is very simple. it is to open a new window:
<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>

Next we will talk about how to display the details of a product, which is similar to the methods we commonly use to display posts in forums.

* ******* The file that displays detailed information ***********
Detail. php

<? Php
Include "config. inc. php ";

// Display product details
// Use global variables to obtain the values of multiple fields.
// There are IDs, names, prices, descriptions, current prices, units, images, and end times.
Function ReadDetail (){
Global $ WARE_TABLE;
Global $ id, $ name, $ price, $ description, $ cprice, $ unit, $ image, $ endtime;

$ SQL = "select id, name, description, price, unit, endtime, reply, curprice, photo from $ WARE_TABLE where id = '$ ID '";
$ Result = mysql_query ($ SQL) or die (mysql_error ());

// You can also use list (...) but I am used to this separation, which seems troublesome, but it is clear that this is necessary, especially when there are fields to be processed.

$ Row = mysql_fetch_array ($ result );
$ Name = $ row [name];
$ Price = $ row [price];
$ Description = $ row [description];
$ Unit = $ row [unit];
$ Cprice = $ row [curprice];
$ Endtime = date ("Y-m-j", $ row [endtime]);
If ($ row [photo] = 1) $ image = $ row [id]. ". jpg ";
Else $ image = "";
}

// Read the latest 10 buyers
Function ReadBuyer (){
Global $ BID_TABLE;
Global $ id, $ buyer, $ buyprice, $ date, $ num;

$ SQL = "select id, buyer, email, price from $ BID_TABLE where parentid = '$ ID' order by id desc ";
$ Result = mysql_query ($ SQL) or die (mysql_error ());
$ K = mysql_num_rows ($ result );

$ Num = ($ k> 10 )? 10: $ k; // Check whether there are more than 10.

For ($ I = 0; $ I <$ num; $ I ){
$ Row = mysql_fetch_array ($ result );
$ Buyer [] = $ row [buyer];
$ Buyprice [] = $ row [price];
$ Date [] = date ("Y-m-j H: I: s", $ row [id]);
}
}


// Display 10 buyers.
Function ShowBuyer (){
Global $ buyer, $ buyprice, $ date, $ num;

For ($ I = 0; $ I <$ num; $ I ){
Echo "<tr> <td width = 25%>". $ date [$ I]. "</td> ";
Echo "<td width = 40%>". $ buyer [$ I]. "</td> ";
Echo "<td width = 35%>". $ buyprice [$ I]. "</td> </tr> ";
}
}

ReadDetail ();
ReadBuyer ();

?>

After the above processing is completed, you can use <? Echo $ name?> Or <? Echo $ price;?> I will not detail the information to be displayed.
This statement is used to display text or images based on whether there are images.
<? If ($ image = "") echo "no photo"; else echo "

When displaying product details, users should also be allowed to make bids. Therefore, I am relatively lazy to make a judgment on the new price of the user, deamweaver is used directly to verify the form, and only the English description is changed to Chinese. However, it is a bit special in judging the new bidding price, so we made some changes to the function generated by dw.

<Script language = "JavaScript">
<! --
Function MM_findObj (n, d) {// v3.0
Var p, I, x; if (! D) d = document; if (p = n. indexOf ("? ")> 0 & parent. frames. length ){
D = parent. frames [n. substring (p 1100000000.doc ument; n = n. substring (0, p );}
If (! (X = d [n]) & d. all) x = d. all [n]; for (I = 0 ;! X & I <d. forms. length; I) x = d. forms [I] [n];
For (I = 0 ;! X & d. layers & I <d. layers. length; I) x?mm_findobj(n,d.layers= I =.doc ument); return x;
}

Function MM_validateForm () {// v3.0
Var I, p, q, nm, test, num, min, max, errors = '', args = MM_validateForm.arguments;
For (I = 0; I <(args. length-2); I = 3) {test = args [I 2]; val = MM_findObj (args [I]);
If (val) {nm = val. name; if (val = val. value )! = ""){
If (test. indexOf ('ismail ')! =-1) {p = val. indexOf ('@');
If (p <1 | p = (val. length-1) errors = '-'nm' must be the correct email address. N ';
} Else if (test! = 'R') {num = parseFloat (val );
If (val! = ''Num) errors = '-'nm' must be a value. N ';
If (test. indexOf ('range ')! =-1) {p = test. indexOf (':');
Min = test. substring (8, p); max = test. substring (p 1 );
*********
Var k = (num-min)/max;
// Determine whether the value is greater than the current price and an integer multiple of the price unit.
If (num <min | k! = Math. ceil (k) errors = '-'nm' must be greater than 'min' and the markup must be an integer multiple of 'Max '. n ';
}}} // ********* End change ********
Else if (test. charAt (0) = 'r') errors = '-'nm' must be complete. N ';}
} If (errors) alert ('found error: n' errors );
Document. MM_returnValue = (errors = '');
}
// -->
</Script>

The following is simple. What else do you need? Show the items that have ended the bidding. The implementation of this function is the same as that of displaying unfinished products. The only difference is that the SetCondition () condition is different and there is no user bidding form when displaying the detail of the product that ends the bidding.

In addition, I will discuss how to add new products.

<? Php
Include "config. inc. php ";
Include "tview. class. php ";

Function AddRecord (){
Global $ view;
// The following variables are obtained from the form on the previous page.
Global $ name, $ price, $ unit, $ year, $ month, $ day, $ photofile, $ intro;

$ T = time ();
$ C = nl2br ($ intro );
$ Et = mktime (24, 0, 0, $ month, $ day, $ year );

// Determine whether a graph has been uploaded.
$ Ph = ($ photofile! = "None" and! Empty ($ photofile ))? '1': '0 ';

// Call the add () parameter of the member function, which is the string in the value () of the SQL statement.
$ View-> Add ("'$ t',' $ name', '$ C',' $ price', '$ unit', '$ et ', '0', '$ price',' $ pH '");

// Copy an image to a specified directory.
If ($ ph = '1 ')
Copy ($ photofile, "photo/$t.jpg ");

}

If ($ Submit ){
$ View = new TViewPage ($ WARE_TABLE, 20 );
AddRecord ();
Header ("Location: manager.htm ");
}

?>

Well, Luo luochao wrote two articles. I don't know if I can add a few more. :)

If you have any questions, please come up and discuss them. I just took out the program. if you see anything inappropriate, never be stingy. please let me know.

My email: ycshowtop@21cn.com

In addition, if you want the complete code of this program, you can also send an email to me.

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.