SoFunction
Updated on 2025-04-09

PHP implementation framework for online auction system (II)

Last time I finished displaying the product list. Let’s talk about the method of displaying product details, which is similar to the method of displaying posts we commonly use in forums.

*******File showing details****************


<?php
include "";

//Show product details
//It can be used to make it easier to get the values ​​of multiple fields.
//There are 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 can also be done with list(...), but I am used to separating it like this, which seems a bit troublesome, but it is clearer, especially when there are fields to be processed, so it is very 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 buyer 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)? 10:$k; //Judge whether 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]);
}
}


//Show 10 buyer information.
function ShowBuyer(){
global $buyer,$buyprice,$date,$num;

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

ReadDetail();
ReadBuyer();

?>

After completing the above processing, you can use <? echo $name?> or <? echo $price;?> etc. in html to get the information to be displayed. I will not explain these in detail.
This is the sentence, and the text or pictures should be displayed separately according to whether there are pictures.
<? if($image=="") echo "No photo"; else echo "<img src=photo/$image>"; ?>



When displaying the product details, users should also be allowed to bid, so at this time, they should make a judgment on the new price set by the user. I am lazy, so I directly use deamweaver to verify this form, and only change the English description in it to Chinese. However, because it is a bit special in judging the new bid, I made a little changes to the function generated by dw.

<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v3.0
var p,i,x; if(!d) d=document; if((p=("?"))>0&&) {
d=[(p+1)].document; n=(0,p);}
if(!(x=d[n])&&) x=[n]; for (i=0;!x&&i<;i++) x=[i][n];
for(i=0;!x&&&&i<;i++) x=MM_findObj(n,[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<(-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=; if ((val=)!="") {
if (('isEmail')!=-1) { p=('@');
if (p<1 || p==(-1)) errors+='- '+nm+' must be the correct email address.n';
} else if (test!='R') { num = parseFloat(val);
if (val!=''+num) errors+='- '+nm+' must be a numerical value.n';
if (('inRange') != -1) { p=(':');
min=(8,p); max=(p+1);
//************ Changes*************
var k=(num-min)/max;
//Judge it should be greater than the current price and is an integer multiple of the current price + the markup unit
if (num<min || k != (k) ) errors+='- '+nm+' must be greater than '+min+' and the markup must be an integer multiple of '+max+'.n';
} } } //*********End the change part**********
else if ((0) == 'R') errors += '- '+nm+' to fill in full.n'; }
} if (errors) alert('The error is found as follows:n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>

The following matter is simple, what else should I do? Show the items that have finished bidding. The implementation of this function is the same as the method of displaying unfinished products, so I won't go into details. The only difference is that the SetCondition() conditions are different and when the product details that ended the bidding, there is no user bid form.


In addition, I will give you a way to add new products.

<?php
include "";
include "";

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

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

//Judge whether there are pictures uploaded.
$ph=( $photofile!="none" and !empty($photofile) )? '1':'0';

//Calling the member function add() parameter is the string in values() in the sql statement
$view->Add("'$t','$name','$c','$price','$unit','$et','0','$price','$ph'");

//If there is a picture, copy it to the specified directory.
if($ph=='1')
copy($photofile,"photo/$");

}

if( $Submit){
$view= new TViewPage($WARE_TABLE,20);
AddRecord();
header("Location:");
}

?>

Okay, I wrote two articles, but I don’t know if I can add a few hundred points. :)

If you have any questions, please sincerely ask everyone to discuss. I have taken out the program. If you see anything inappropriate and inappropriate, don’t be stingy. Remember to tell me.

My email: ycshowtop@

In addition, if you want the code for this program, please email it and I will send it to you.