0

我正在尝试做一个购物画廊。我设法显示了我的数据库表的第一行内容(内容包括:产品的图像缩略图、产品名称和产品价格)。现在我正在尝试显示我的表格的第二行内容。我该怎么做呢?当我尝试它时,PHP 仍然显示所有第一行的内容。

HTML 代码:

<div id="Dress1"> 
   <a href="Prod1.php"><img id="Image1" src="../imgs/thumb/<?=$imgsml?>"></a> 
   <p id="ProductCodeText"> 
   <?php echo $prd_name;?><br/>Price: <?php echo $price; ?> &nbsp;Php</p> 
    </div>

    <div id="Dress2"> 
    <a href="Prod2.php"><img id="Image1" src="../imgs/thumb/<?=$imgsml?>"></a> 
    <p id="ProductCodeText"> 
    <?php echo $prd_name;?><br/>Price: <?php echo $price; ?> &nbsp;Php</p> 
    </div>

然后是 Dress3 和 4

PHP代码:

<?php  include_once("../incs/dbcon.php"); 

if ($_SERVER['REQUEST_METHOD'] == "POST") {
$prd_id = $_REQUEST["prd_id"];
$sub_id = $_REQUEST["sub_id"];
$prd_name = $_REQUEST["prd_name"];
$descr = $_REQUEST["descr"];
$price = $_REQUEST["price"];
$sizes = $_REQUEST["sizes"];
/*$imgsml = $_REQUEST["imgsml"];
$imgbig = $_REQUEST["imgbig"];*/
$featured = $_REQUEST["featured"];
$prd_status = $_REQUEST["prd_status"];
$colors = $_REQUEST["colors"];
$prd_code = $_REQUEST["prd_code"];
$date_release = $_REQUEST["date_release"];
$stk_status = $_REQUEST["stk_status"];
$ctr_id = $_REQUEST["ctr_id"];
$price_sale = $_REQUEST["price_sale"];
$onsale = $_REQUEST["onsale"];
$mostPopular = $_REQUEST["mostPopular"];
$mn = $_REQUEST["mn"];
$year = $_REQUEST["year"];
$imagewidth = $_REQUEST["imagewidth"];
$newArrival = $_REQUEST["newArrival"];
$cat_name = $_REQUEST["cat_name"];
$sub_name = $_REQUEST["sub_name"];

if (isset($_POST['prd_id'])) $prd_id = mysql_real_escape_string($_POST['prd_id']);
    if (isset($_POST['sub_id'])) $sub_id = mysql_real_escape_string($_POST['sub_id']);
    if (isset($_POST['prd_name'])) $prd_name = mysql_real_escape_string($_POST['prd_name']);
    if (isset($_POST['descr'])) $descr = mysql_real_escape_string($_POST['descr']);
    if (isset($_POST['price'])) $price = mysql_real_escape_string($_POST['price']);
    if (isset($_POST['sizes'])) $sizes = mysql_real_escape_string($_POST['sizes']);
    if (isset($_POST['imgsml'])) $imgsml = mysql_real_escape_string($_POST['imgsml']);
    if (isset($_POST['imgbig'])) $imgbig = mysql_real_escape_string($_POST['imgbig']);  
    if (isset($_POST['featured'])) $featured = mysql_real_escape_string($_POST['featured']);
    if (isset($_POST['prd_status'])) $prd_status = mysql_real_escape_string($_POST['prd_status']);
    if (isset($_POST['colors'])) $colors = mysql_real_escape_string($_POST['colors']);
    if (isset($_POST['prd_code'])) $prd_code = mysql_real_escape_string($_POST['prd_code']);
    if (isset($_POST['date_release'])) $date_release = mysql_real_escape_string($_POST['date_release']);    
    if (isset($_POST['stk_status'])) $stk_status = mysql_real_escape_string($_POST['stk_status']);
    if (isset($_POST['ctr_id'])) $ctr_id = mysql_real_escape_string($_POST['ctr_id']);  
    if (isset($_POST['price_sale'])) $price_sale = mysql_real_escape_string($_POST['price_sale']);  
    if (isset($_POST['onsale'])) $onsale = mysql_real_escape_string($_POST['onsale']);          
    if (isset($_POST['mostPopular'])) $mostPopular = mysql_real_escape_string($_POST['mostPopular']);
    if (isset($_POST['mn'])) $mn = mysql_real_escape_string($_POST['mn']);
    if (isset($_POST['year'])) $year = mysql_real_escape_string($_POST['year']);
    if (isset($_POST['imagewidth'])) $imagewidth = mysql_real_escape_string($_POST['imagewidth']);
    if (isset($_POST['newArrival'])) $newArrival = mysql_real_escape_string($_POST['newArrival']);
    if (isset($_POST['cat_name'])) $cat_name = mysql_real_escape_string($_POST['cat_name']);
    if (isset($_POST['sub_name'])) $sub_name = mysql_real_escape_string($_POST['sub_name']);
}

$szQuery = "SELECT * FROM products";
$rs = mysql_query($szQuery) or die(mysql_error()."<br>$szQuery");
if ($row = mysql_fetch_object($rs))
{
$prd_id = $row->prd_id; 
$sub_id = $row->sub_id; 
$prd_name = $row->prd_name;
$descr = $row->descr;
$price = $row->price;
$sizes = $row->sizes;
$imgsml = $row->imgsml;
$imgbig = $row->imgbig;
$featured = $row->featured;
$prd_status = $row->prd_status;
$colors = $row->colors;
$prd_code = $row->prd_code; 
$date_release = $row->date_release; 
$stk_status = $row->stk_status;
$ctr_id = $row->ctr_id;
$price_sale = $row->price_sale;
$onsale = $row->onsale;     
$mostPopular = $row->mostPopular;
$mn = $row->mn;
$year = $row->year;
$imagewidth = $row->imagewidth;
$newArrival = $row->newArrival;
$cat_name = $row->cat_name;
$sub_name = $row->sub_name;
}
?>

我尽可能需要一个愿意一步一步耐心地教我的人。哦,是的,我是 MySQL 和 PHP 的新手。

4

2 回答 2

2

这可能会对您有所帮助。看看这个例子

<?php
            $result=mysql_query("SELECT * FROM elternplaner");
            while($row=mysql_fetch_array($result))
            {
            ?>
            <tr>
                <td align='center'>
                       <input type="checkbox" name="check[]">
                </td>
                <td align="center"><a href="edit.php?iId=<?php print($row['iId']); ?>" ><img src="edit.png" width=30px title="Edit"></a>&nbsp;<a href="delete.php?iId=<?php print($row['iId']); ?>"><img src="delete.png" title="Delete" width=30px></a></td>
                <td align="center"><?php print($row['vName']) ?></td>
                <td align="center"><?php print($row['eGender']) ?></td>
                <td align="center"><?php print($row['dBirthDate']) ?></td>
                <td align="center"><?php print($row['vEmail']) ?></td>
                <td align="center"><?php print($row['iPhoneNo']) ?></td>
                <td align="center"><?php print($row['vLocation']) ?></td>
                <td align="center"><?php print($row['dtLastLoginDate']) ?></td>
                <td align="center"><?php print($row['dtMemberSince']) ?></td>
                <td align="center"><?php print($row['eStatus']) ?></td>
            </tr>
            <?php } ?>

这将返回整个表

于 2012-07-18T04:37:45.957 回答
0

示例代码应该是这样的:

$query = "SELECT * FROM ......."
$resultset = mysql_query($query);

while($row = mysql_fetch_assoc($resultset)) {
    $rows[] = $row;
}

现在您可以使用循环遍历 $rows 数组。

于 2012-07-18T04:41:39.600 回答