PHP Implementation framework of online auction system (II.)

Source: Internet
Author: User
Tags date config copy include integer min variables
Last time I finished the list display method of the goods. 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

<?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.

<?php
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.