在线竞拍系统的PHP实现框架(二)
********显示详细信息的文件***********
detail.php
<?php
include "config.inc.php";
//显示商品详细信息
//用全局变量来做,可以方便地取到多个字段的值。
//有id,名字,价格,介绍,当前价,单位,图片,结束时间。
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());
//下面这一句,也可以用list(...)来做,但我习惯这样分开,看起来是麻烦点,不过清楚些,特别是有要处理的字段时,这样就很有必要了。
$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="";
}
//读最新10个买家信息
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; //判断一下,是不是多于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]);
}
}
//显示10个买家信息。
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();
?>
完成了上面的处理,就可以html中用<? echo $name?>或<? echo $price;?>等来取到要显示的信息了,这些我就不详述了。
就是这句,要根据是否有图片分别显示文字或图片。
<? if($image=="") echo "没有照片"; else echo "<img src=photo/$image>"; ?>
在显示商品详细资料时,也应让用户可以投标,所以此时要对用户下的新价做出一个判断,我比较懒,就直接用deamweaver来做这个表单的校验了,只把其中的英文说明改成中文,不过由于在判断新出价的方面有点特殊,所以对dw生成的函数做了一点点改动。
<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+' 必须是正确的email地址.n';
} else if (test!='R') { num = parseFloat(val);
if (val!=''+num) errors+='- '+nm+' 必须是数值.n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
//**********改动部分*********
var k=(num-min)/max;
//判断要大于当前价,并且是当前价+加价单位的整数倍
if (num<min || k != Math.ceil(k) ) errors+='- '+nm+' 必须是大于 '+min+' 并且加价必须为 '+max+'的整数倍.n';
} } } //*******结束改动部分********
else if (test.charAt(0) == 'R') errors += '- '+nm+' 要填完整.n'; }
} if (errors) alert('发现错误如下:n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
下面的事就简单了,还要有什么呢?显示一下已结束竞标的商品吧。这个功能的实现与显示未结束的商品方法一样,我就不罗嗦了。唯一的区别在于一是SetCondition()条件的不同和在显示结束竞价的商品详细资料时,没有用户出价的表单。
另外,我再给出添加新商品的方法吧。
<?php
include "config.inc.php";
include "tview.class.php";
function AddRecord(){
global $view;
//以下变量都是从上一个页面的表单中得到的。
global $name,$price,$unit,$year,$month,$day,$photofile,$intro;
$t=time();
$c=nl2br($intro);
$et=mktime(24,0,0,$month,$day,$year);
//判断一下是否有图上传了。
$ph=( $photofile!="none" and !empty($photofile) )? '1':'0';
//调用成员函数add()参数就是sql语句中的values()中的字串
$view->Add("'$t','$name','$c','$price','$unit','$et','0','$price','$ph'");
//如果有图片,拷到指定目录下。
if($ph=='1')
copy($photofile,"photo/$t.jpg");
}
if( $Submit){
$view= new TViewPage($WARE_TABLE,20);
AddRecord();
header("Location:manager.htm");
}
?>
好了,罗罗嗦嗦写了两篇,不知道可不可以又加个几百分哦。:)
有什么问题真心地请大家提出来讨论,我可是把程序拿出来了,您见到什么不妥的不当的,可千万不要吝啬,记得告诉我一声。
我的email : ycshowtop@21cn.com
另外,如果你想要这个程序比较完整的代码,也来个email,我寄给您。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The enumeration function in PHP8.1 enhances the clarity and type safety of the code by defining named constants. 1) Enumerations can be integers, strings or objects, improving code readability and type safety. 2) Enumeration is based on class and supports object-oriented features such as traversal and reflection. 3) Enumeration can be used for comparison and assignment to ensure type safety. 4) Enumeration supports adding methods to implement complex logic. 5) Strict type checking and error handling can avoid common errors. 6) Enumeration reduces magic value and improves maintainability, but pay attention to performance optimization.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

RESTAPI design principles include resource definition, URI design, HTTP method usage, status code usage, version control, and HATEOAS. 1. Resources should be represented by nouns and maintained at a hierarchy. 2. HTTP methods should conform to their semantics, such as GET is used to obtain resources. 3. The status code should be used correctly, such as 404 means that the resource does not exist. 4. Version control can be implemented through URI or header. 5. HATEOAS boots client operations through links in response.

In PHP, exception handling is achieved through the try, catch, finally, and throw keywords. 1) The try block surrounds the code that may throw exceptions; 2) The catch block handles exceptions; 3) Finally block ensures that the code is always executed; 4) throw is used to manually throw exceptions. These mechanisms help improve the robustness and maintainability of your code.

The main function of anonymous classes in PHP is to create one-time objects. 1. Anonymous classes allow classes without names to be directly defined in the code, which is suitable for temporary requirements. 2. They can inherit classes or implement interfaces to increase flexibility. 3. Pay attention to performance and code readability when using it, and avoid repeatedly defining the same anonymous classes.
