gpt4 book ai didi

php - 如何在 PHP 中显示数据库的所有表行内容?

转载 作者:行者123 更新时间:2023-11-29 08:49:58 25 4
gpt4 key购买 nike

我正在尝试做一个购物廊。我成功地显示了数据库表的第一行内容(内容包括:产品的图像缩略图、产品名称和产品价格)。现在我正在尝试显示表格的第二行内容。我该怎么做呢?当我尝试时,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>

然后是裙子3和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 新手。

最佳答案

这可能对你有帮助。看看这个例子

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

这将返回整个表格

关于php - 如何在 PHP 中显示数据库的所有表行内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11534333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com