gpt4 book ai didi

php - 当选择类别链接时,显示我的产品页面中选定类别的所有图像 - php Mysql

转载 作者:行者123 更新时间:2023-11-29 13:26:35 24 4
gpt4 key购买 nike

我想在选择类别链接时显示我的产品页面中选定类别的所有图像。我的数据库表有“id”、“name”、“size”、“category_id”、“image_path”。我上传图像以及保存到数据库和选定的类别都工作正常,我有一个可以从数据库中删除并且工作正常的页面。我的 products.php 文件如下,如果有人可以提供帮助,我需要帮助。

<?php 
require_once ("Includes/session.php");
require_once ("Includes/simplecms_config.php");
require_once ("Includes/connectDB.php");
include("Includes/header.php");
confirm_is_admin();
?>
<section>
<?php
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$category_id = $_GET['category_id'];

$query = mysqli_query($databaseConnection, "SELECT * FROM products WHERE category_id = '".$category_id."'");

echo '<div id="main_products">';

echo '<h1 style="margin-left: 85px;">Golf '.$category_id.'</h1><br /><br />';

$row_count = mysqli_num_rows($query);
if ($row_count == 0) {
echo '<p style="color:red">There are no images uploaded for this category</p>';
} elseif ($query) {

echo '<table style="text-align:center;">';


while($prod = mysqli_fetch_array($query))
{
echo '<tr><td>';

$file = $prod['/Golfsite/uploads/'];
$name = $prod['name'];
$id = $prod['id'];
$category_id = $prod['category_id'];
$image_path = $prod['image_path'];

echo '<img src="'.$file.'" height="150" width="175" margin="10" float="center" border="0" title="'.$name.'" />';

echo '</td></tr>';
}
echo '</table>';
}
else
{
die('There was a problem with the query: ' .$query->error);
}
?>

</div>
</section>
<br />
<?php
include ("Includes/footer.php");
?>

最佳答案

首先检查您的$_GET['category_id']值,该变量中包含什么内容,如果这是选择正确的类别值,然后回显您的sql查询并运行此查询进入你的mysql数据库并查看结果。如果结果集正确,则查询是正确的,否则这两种情况之间存在问题。

关于php - 当选择类别链接时,显示我的产品页面中选定类别的所有图像 - php Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20040261/

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