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

时间:2013-11-18 04:44:51

标签: php mysql

我希望在选择类别链接时,从所选类别中显示我的产品页面中的所有图像。我的数据库表有'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");
?>

1 个答案:

答案 0 :(得分:1)

首先检查你的 $ _ GET ['category_id'] 值,这个变量是什么,如果这是选择正确的类别值,那么去回显你的sql查询并运行这个查询进入你的mysql数据库并查看结果。如果结果集正确,则查询正确,否则这两种情况之间存在问题。