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
[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
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.
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);
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
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;}
< End Function definition, main program body *************
Constructs this viewpage class, gives the commodity table and each page displays the number of rows
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>
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.