PHP Implementation Framework for online auction system (i) _php Foundation

Source: Internet
Author: User
Tags echo date function definition prev 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.

<?php
/*********************************************
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= "";
}


Set Display Criteria *********
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;
}

Set Delivery 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 ());
}


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

Show Page Buttons *************
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

<?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
//*****************
//
<?php
Include "config.inc.php";
Include "tview.class.php"; class file


Show list of items ********
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>";
}
}

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

}


Show 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 "<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 *************
Constructs this viewpage class, gives the commodity table and each page displays the number of rows

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

?>

Here is a use of a JS function bar, very simple, 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>

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.