PHP Implementation framework of online auction system

Source: Internet
Author: User
Tags date array function definition variables table name time limit mysql database phpmyadmin

Before I gave a page to show the MySQL record class, but did not give the use of the example, now, I have just written an online auction system framework program to illustrate the use of this class, but also on the online auction implementation methods to discuss with you.

First of all, I am not a master, is not an expert, but a fans, so this program must have a lot of loopholes, but I dare to take out, because I very much hope to be free to share with you PHP to bring us happiness. (actually want to add a bit more points to get a support for MySQL space ^_^)


I think the auction system and the general supply and demand information distribution system, the biggest difference is two points, the point is that the new price of the bidder to be reflected in the price of goods in a timely manner, another point is the time limit, in the end of the bid, we will stop the bid. And give the winner of the final bid.

Other I have not thought of, have the expert to point to introduce bar.

So, I want to put a supply and demand information system into a bidding system should not be difficult.

Next to the new version of the Tviewpage class and database structure.

/*********************************************
Tviewpage v 1.2

Pagination displays the MySQL database record class

Author: sharetop
E-mail:ycshowtop@21cn.com
Time: 2000-8-31

[2000-9-6] 1.2
Fixed a bug in ReadList () to put the validation offset into the class.
Add Add () Delete () modify () three basic action functions.

This class does not provide the ability to connect to the database, so you need to open the appropriate database externally.
This class also does not provide the ability to display records, except that paging reads records to a result two-dimensional array.
You need to customize the data display format externally.
***********************************************/
Class Tviewpage {

var $Table; Table name
var $MaxLine; Show number of rows per page

var $Offset; Record offset
var $Total; Total Records
var $Number; Number of records read on this page
var $Result; read out the results

var $TPages; Total pages
var $CPages; Current page

var $Condition; Display criteria such as: where id= ' $id ' ORDER by id DESC
var $PageQuery; Pagination shows the parameters to pass

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

//******** setting Display conditions *********
such as: where id= ' $id ' ORDER by id DESC
The requirement is a string that conforms to the SQL syntax (this string will be added to the SQL statement)

function Setcondition ($s) {
$this->condition= $s;
}

//****** Setting pass parameters ************
Value of key parameter name value
such as: Setpagequery ("id", $id), if you have more than one parameter to pass, you can call this function multiple times.

function Setpagequery ($key, $value) {
$tmp [key]= $key; $tmp [value]= $value;
$this->pagequery[]= $tmp;
}

//******** Read Records ***************
Primary work function, reading the corresponding record from the table according to the conditions given
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) {//Condition according to 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 for 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 **********
Call Setcondition () first to determine the condition.

function Delete () {
$SQL = "DELETE from". $this->table. " ". $this->condition;
mysql_query ($SQL) or Die (Mysql_error ());
}

Modify Records ************
$field Field name $value new value
If you want to modify multiple fields, you can repeat the function.

function Modify ($field, $value) {
$SQL = "UPDATE from". $this->table. " SET ". $field." = ". $value." ". $this->condition;
mysql_query ($SQL) or Die (Mysql_error ());
}

//********** Display pages *************
Show current page and total pages

Function thepage () {
$this->tpages=ceil ($this->total/$this->maxline);
$this->cpages= $this->offset/$this->maxline+1;
echo "->cpages". $this. " Page/Total ". $this->tpages." Page ";
}

//********** Display page button *************
This function is called after the thepage () function!!!
Displays the first page, next page, top, and last page, plus the parameters to pass

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 string to pass the parameter number
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. " > Home </a>| ";
if ($prev >=0)
echo "<a Href= $PHP _self?offset=". $prev. $strQuery. " > On a 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 </a> ";
}

End Class
}

?>

//************************
Ebid.sql file (I was exported using phpMyAdmin)

# phpMyAdmin Mysql-dump
# http://www.htmlwizard.net/phpMyAdmin/
#
# Host:localhost Database:ebid

# --------------------------------------------------------
# Table structure for table ' reply '
# ID, commodity ID, bidder, bidder's email, bid.

CREATE TABLE Reply (
ID varchar not NULL,
ParentID varchar () not NULL,
Buyer varchar (a) not NULL,
Email varchar not NULL,
Price float (10,2) DEFAULT ' 0.00 ' is not NULL,
PRIMARY KEY (ID, price)
);


# --------------------------------------------------------
# Table structure for table ' shop '
# ID, product name, Introduction, original price, fare increase unit, end time, bid number, current price, whether there are photos

CREATE TABLE Shop (
ID varchar not NULL,
Name varchar not NULL,
Description text,
Price float (10,2) DEFAULT ' 0.00 ' is not NULL,
Unit tinyint (2) unsigned not NULL,
Endtime varchar 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


$HOST = "localhost"; Host Name
$DATABASE = "ebid"; Database name
$WARE _table= "Shop"; Product List
$BID _table= "Reply"; Response table
$USER = "root"; User
$PASSWD = "9999"; Password

$PAGE _max_line=20; Show number of rows per page

Open Database
$LinkID =mysql_connect ($HOST, $USER, $PASSWD);
mysql_select_db ($DATABASE, $LinkID) or Die (Mysql_error ());

?>

Here are the functions that show goods and TOP10 products
//*****************
//
Include "config.inc.php";
Include "tview.class.php"; class file

//***** Display product List ********
function Printlist () {
Global $view;

$ct =time ();

Set the sentence for the condition! To satisfy the SQL syntax Oh. Show only goods that have not finished bidding
$view->setcondition ("Where endtime> ' $ct ' ORDER by id DESC");

Calling member functions to read records
The 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&GT;<TD width=15% >";
echo Date ("Y-m-j 24:00:00", $result [$i][endtime]);
echo "</TD&GT;<TD width=15% Align=right>¥";
echo $result [$i][curprice];
echo "</TD&GT;<TD width=10% align=right>";
echo $result [$i][reply];
echo "</td></tr>";
}
}

//********* shows the hottest 10 records **********
function Listtophot () {
Global $view;

Also set the criteria first
$view->setcondition ("Order by reply Desc");
Read Records
$result = $view->readlist ();

$k = (count ($result) >10)? ' A ':(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>";
}

}

//********* Displays the latest 10 records ***********
function listtopnew () {
Global view;

$view->setcondition ("ORDER by id DESC");
$result = $view->readlist ();

$k = (count ($result) >10)? ' A ':(count ($result));

for ($i =0; $i $k; $i + +) {
echo " echo " echo "}
}


//**********< End Function definition, main body *************
//construct this viewpage class, give the merchandise table and show the number of rows per page

$ View=new tviewpage ($WARE _table, $PAGE _max_line);

?>

gives you a JS function to use, very simply, to open a new window:
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 ");
}

Let's talk about how to display the details of the product, which is similar to the way we usually display posts in the Forum.

A file that displays detailed information ***********
detail.php

Include "config.inc.php";

Show Product Details
With global variables, you can easily fetch values from multiple fields.
Have ID, name, price, Introduction, current price, unit, picture, end time.
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 ());

The following sentence, you can also use the list (...) To do, but I am accustomed to this separation, it seems to be a point of trouble, but clearly, especially with the fields to be processed, so it is necessary.

$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 information
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)? $k; Judge if 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]);
}
}


Displays 10 buyer information.
function Showbuyer () {
Global $buyer, $buyprice, $date, $num;

for ($i =0; $i $num; $i + +) {
echo "<TR&GT;<TD width=25%>". $date [$i]. " </td> ";
echo "<TD width=40%>". $buyer [$i]. " </td> ";
echo "<TD width=35%>". $buyprice [$i]. " </td></tr> ";
}
}

Readdetail ();
Readbuyer ();

?>

The above processing can be done in HTML. echo $name?> or? Echo $price;? > etc to get the information to be displayed, I will not elaborate.
This is the sentence, according to whether there are pictures of the text or pictures.
? if ($image = = "") echo "no photo"; else echo "

When displaying the details of the product, also should let the user can bid, so at this time to the user to make a judgment, I am lazy, directly with deamweaver to do this form of the check, only the English note to change into Chinese, but because in judging the aspect of the new bid is a little special, So a little bit of change is made to the functions that DW generates.

<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+1)].document; 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].document); 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 (' Isemail ')!=-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 numeric. N ';
if (Test.indexof (' InRange ')!=-1) {P=test.indexof (': ');
Min=test.substring (8,P); Max=test.substring (p+1);
Change Part *********
var k= (num-min)/max;
Judge to be more than the current price, and is the current price + unit of increase in integer times
if (Num<min | | | k!= Math.ceil (k)) errors+= '-' +nm+ ' must be greater than ' +min+ ' and the fare increase must be ' +max+ ' integer times. N ';
//******* end part of the change ********
else if (test.charat (0) = = ' R ') errors + = '-' +nm+ ' to fill in complete. N '; }
} if (Errors) alert (' Discovery error is as follows: N ' +errors);
Document. Mm_returnvalue = (Errors = = ");
}
-->
</script>

The following things are simple, what else do you want? Show the goods that have finished bidding. The implementation of this function is the same as showing the unfinished product method, I will not wordy. The only difference is that the setcondition () condition differs and there is no user bid form when the product details are displayed at the end of the auction.

Besides, I'll give you a way to add a new product.

Include "config.inc.php";
Include "tview.class.php";

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

$t =time ();
$c =nl2br ($intro);
$et =mktime (24,0,0, $month, $day, $year);

Judge if there are any pictures uploaded.
$ph = ($photofile!= "None" and!empty ($photofile))? ' 1 ': ' 0 ';

The Call member function add () parameter is the string in the values () in the SQL statement
$view->add (' $t ', ' $name ', ' $c ', ' $price ', ' $unit ', ' $et ', ' 0 ', ' $price ', ' $ph ');

If you have a picture, copy it to the specified directory.
if ($ph = = ' 1 ')
Copy ($photofile, "photo/$t. jpg");

}

if ($Submit) {
$view = new Tviewpage ($WARE _table,20);
AddRecord ();
Header ("Location:manager.htm");
}

?>

Well, RR has written two, don't know can add a hundreds of points oh. :)

There is any problem sincerely please put forward to discuss, I have to take out the program, you see what improper, but don't be stingy, remember to tell me.

My email:ycshowtop@21cn.com.

In addition, if you want this program more complete code, also an email, I sent to you.



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.