竞拍价格是一个流程,实际上是这样的:

  • display展示界面->get方式a标签链接传递主键到具体信息页面->get方式a标签传递主键到写拍卖价格的页面->php处理->回到display

      这里面我觉得重点的就是get传递和接收,然后还有自己的一些语法也蛮重要的。

     &nbspdisplay的代码已经给过,下面给detail的代码:

<!--detail.php:显示商品详细信息-------------------->
<?php 
//include "sys_conf.inc";

/******************************************
函数名:    get_goods_detail_info()
功能:     获取编号为$gid的商品详细信息
输入:     商品编号
输出:     详细信息,存放在全局变量中
******************************************/
function get_goods_detail_info($gid)
{ 
    //使用全局变量返回多个字段的结果,具体包括名字,初始价格,介绍,当前价格,单位,图片,结束时间
    global $name,$init_price,$description,$current_price,$unit,$photodir,$endtime; 

    //连接数据库
    $DBHOST="localhost";
    $DBUSER="root";
    $DBPWD="";
    $DBNAME="auction";

    //每页显示记录数
    $PAGE_MAX_LINE=5;
    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
    mysql_select_db($DBNAME); 

    //查询    
    $SQL="select * from goods where gid='$gid'"; 
    $result=mysql_query($SQL) or die(mysql_error());    

    //获取详细信息    
    $row=mysql_fetch_array($result); 
    $name=$row["name"]; 
    $init_price=$row["init_price"]; 
    $description=$row["description"]; 
    $unit=$row["unit"]; 
    $endtime=$row["endtime"]; 
    $current_price=$row["current_price"]; 
    if($row["photodir"]!="") $photodir=$row["photodir"];
    else $photodir=""; 

    //显示详细信息,使用<table>
    echo "<table width='80%' border='1' align='center'>";
    echo "<tr><td>商品名</td><td>$name</td></tr>"; 

    echo "<tr><td>商品图片</td><td>";
    if(isset($photodir) && $photodir!="")
        echo "<img src=./upload_image/$photodir>";
    echo "</td></tr>"; 

    echo "<tr><td width=20%>介绍</td><td>$description</td></tr>"; 
    echo "<tr><td>单位</td><td>$unit</td></tr>"; 
    echo "<tr><td>初始价格</td><td>¥$init_price</td></tr>"; 
    echo "<tr><td>目前最高价</td><td>¥$current_price</td></tr>"; 
    echo "<tr><td>结束时间</td><td>$endtime</td></tr>";    
    echo "</table>";

    //显示买家信息
    echo "<center>买家信息</center>";
    get_reply_detail_info($gid);   
} 

/******************************************
函数名:    get_reply_detail_info()
功能:     显示买家信息
输入:     商品编号
输出:     对商品$gid出价的所有买家信息,存放在全局变量中
******************************************/
function get_reply_detail_info($gid)
{ 
    //使用全局变量返回多个字段的结果,具体包括名字,价格
    global $name,$buyprice; 

    //连接数据库
    $DBHOST="localhost";
    $DBUSER="root";
    $DBPWD="";
    $DBNAME="auction";

    //每页显示记录数
    $PAGE_MAX_LINE=5;
    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);
    mysql_select_db($DBNAME); 

    //查询
    $SQL="select * from reply where gid='$gid' order by reply.rid desc"; 
    $result=mysql_query($SQL) or die(mysql_error()); 

    //获取相信信息
    for($i=0;$i<mysql_num_rows($result);$i++)
    { 
        $row=mysql_fetch_array($result); 
        $buyer[]=$row["bname"]; 
        $buyprice[]=$row["price"]; 
    } 

    //输出
    echo "<table width='80%' border='1' align='center'>";
    echo "<tr bgcolor='green'>"; 
    echo "<td>出价者</td>"; 
    echo "<td>出价</td>"; 
    echo "</tr>";   
    for($i=0;$i<mysql_num_rows($result);$i++)
    { 
        echo "<tr><td>".$buyer[$i]."</td>"; 
        echo "<td>".$buyprice[$i]."</td>"; 
    } 
    echo "</table>";
} 
$gid=$_GET["gid"];
//主程序
get_goods_detail_info($gid);
?> 

<html>
    <head>
        <title>商品详细信息</title>
    </head>
    <body>
    <center>
        <form action='bid.php?<?php echo "gid=$gid"?>' method='post'>
            <input type='submit' name='bid' value="出价">
            <?php echo "gid=$gid"?>
        </form>
    </center>
    </body>
</html>

      还有竞拍写价格的地方:

<?php session_start(); ?>
<!--bid.php:买家出价---------------------------->
<?php



$gid=$_GET["gid"];

if(isset($_GET['hasbid'])&&isset($_POST["price"]))
{
    $gid=$_GET["gid"];
    $hasbid=$_GET["hasbid"];
    $price=$_POST["price"];
    //连接数据库
    include "sys_conf.inc";

    $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);            
    mysql_select_db($DBNAME); 



    //插入reply中数据
    $SQL="insert into reply (bname,gid,price) values('".$_SESSION["user_name"]."',$gid,$price)";
    //echo $SQL;
    $result=mysql_query($SQL,$link_id); //执行查询

    //修改goods中reply_num
    $SQL="update goods set reply_num=reply_num+1";
    $result=mysql_query($SQL,$link_id); //执行查询

    //修改goods中的current_price
    $SQL="select current_price from goods where gid='$gid'"; 
    $result=mysql_query($SQL) or die(mysql_error());   
    $row=mysql_fetch_array($result);  
    if($price>$row["current_price"])
    {
        $SQL="update goods set current_price=$price where gid='$gid'";
        $result=mysql_query($SQL,$link_id); //执行查询        
    } 

    mysql_close($link_id);  

    //转到商品显示页面  
    echo "<script language='javascript'>";  
    echo "alert(\"出价成功!\");";   
    echo "location='display_goods.php';";
    echo "</script>";
}
?>
<html>
    <head>
        <title>买家出价</title>
    </head>
    <body>
    <center>
        <form action='bid.php?hasbid=1&<?php echo "gid=$gid"?>' method='post'>
            价格<input type='input' name='price'>
            <input type='submit' name='bid' value="确定">
        </form>
    </center>
    </body>
</html>
posted on 2015-04-05 08:32  虽然如此  阅读(349)  评论(0编辑  收藏  举报