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

Source: Internet
Author: User
Tags echo date
I gave a page to display the MySQL record class, but did not give an example of the use, 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 method with everyone to discuss.

First of all, I am not a master, is not a connoisseur, just 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 the joy of PHP to us. (actually want to add 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 there are two points, one is the bidder to open the new price to be reflected in the price of goods in a timely manner, another point is the time limit, after the end of the bidding, will stop bidding. And give the final bidder.

I have not thought of the other, some experts to introduce it.

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

Let's start with the new Tviewpage class and database structure.

<?php
/*********************************************
Tviewpage v 1.2

Classes that display MySQL database records in pagination

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

[2000-9-6] 1.2
Fixed a bug in ReadList () that would verify that offset was placed in the class.
Added Add () Delete () modify () three basic operation functions.

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

var $Table; Table name
var $MaxLine; Number of rows displayed per page

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

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

var $Condition; Display conditions 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 *********
Example: where id= ' $id ' ORDER by id DESC
The requirement is a string that conforms to the SQL syntax (this string will be added after the SQL statement)

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

Set the pass parameter ************
Key parameter name value of the value parameter
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;
}

Reading Records ***************
The main work function that reads the corresponding records from the table according to the given conditions
The return value is a two-dimensional array, result[the 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 by 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 values such as "' $id ', ' $name ', ' $class '" etc.

function Add ($STR) {

$SQL = "INSERT into". $this->table. " VALUES (". $str.") ";
mysql_query ($SQL) or Die (Mysql_error ());

}

Deleting Records **********
First call Setcondition () to determine the condition.

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

Modify Record ************
$field Field name $value new value
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 "First". $this->cpages. " Page/Total ". $this->tpages." Page ";
}

Show page Flip Button *************
This function is to be called after the thepage () Function!!!
Display the first page, next page, previous pages, and no pages, 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. " > 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 </a> ";
}

End Class
}

?>


//************************
Ebid.sql file (I exported it with 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, bid.

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


# --------------------------------------------------------
# Table structure for table ' shop '
# ID, product name, Introduction, original price, markup unit, end time, bid number, current price, whether there is a photo

CREATE TABLE Shop (
ID varchar (+) is not NULL,
Name varchar (not NULL),
Description text,
Price Float (10,2) The DEFAULT ' 0.00 ' 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 Form
$USER = "root"; User
$PASSWD = "9999"; Password

$PAGE _max_line=20; Number of rows displayed per page

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

?>

Here are the functions for displaying goods and TOP10 goods
//*****************
//
<?php
Include "config.inc.php";
Include "tview.class.php"; class file


Show Product List ********
function Printlist () {
Global $view;

$ct =time ();

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

Call 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 conditions first
$view->setcondition ("Order by reply Desc");
Read the Record
$result = $view->readlist ();

$k = (count ($result) >10)? ' Ten ':(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 the latest 10 records ***********
function Listtopnew () {
Global $view;

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

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


//********** <结束函数定义,主程序体*************
The End function definition, the main program body *************
//Constructs this viewpage class, gives the commodity table and shows the number of rows per page

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

?>

Given a JS function, it is simple to open a new window:
Function ShowDetail (str) {
WINDOW.O Pen (str, "Newwin", "top=20,left=20,width=600,height=400,
Location=no,toolbar=no,status=no,resizable=no, Scrollbars=yes ");
}

http://www.bkjia.com/phpjc/3 14261.html www.bkjia.com true http://www.bkjia.com/phpjc/314261.html techarticle front I gave a pagination display of MySQL record classes, But I did not give an example of the use, now, I have just written an online auction system framework program to illustrate the use of this class ...

  • Related Article

    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.