用php mysql显示类别的数据

时间:2015-05-01 03:00:21

标签: php mysql categories

我的表是:

  1. barangtbl:id,judul_barang,judul_seo,keywords,deskripsi,id_kat,id_sub,id_supersub,kategori_seo,view,gambar

  2. kategori:id_kat,nama_kat

  3. subkategori:id_sub,id_kat,nama_sub

  4. supersubkategori:id_supersub,id_sub,id_kat,nama_supersub

  5. 我在使用PHP从数据库中显示类别数据时出现问题,问题是当我点击链接:localhost / test / category.php?name = HPI时,它没有显示任何数据,但如果我将HPI更改为数字:15,它显示全部。

    15是在supersubkategori表上的id_supersub数据,我用barangtbl表加入。所以,我想要的只是有人点击:localhost / test / category.php?name = HPI它将显示内部有HPI类别的数据。怎么解决这个问题?

    <?php
    if (isset($_GET['name']))
    {
        $kategori = $_GET['name']; 
    }
    
    include "config.php";
    
    if ((isset($kategori)) =='')
    {
    $query = "SELECT * FROM barangtbl INNER JOIN supersubkategori on supersubkategori.id_supersub = barangtbl.id_supersub ORDER BY id DESC LIMIT 0,12";
    $hasil = mysql_query($query);
    $numrows = mysql_num_rows($hasil);
    }
    else
    {
        echo "
                    <table width=\"100%\">
                        <tr>
                            <td align=\"center\"><b><font color=\"red\" size=\"2.5\">[ ".$_GET['name']." ]</b></font></td>
                        </tr>
                    </table>";
    
        $query = "SELECT * FROM barangtbl WHERE id_supersub = '$kategori' ORDER BY id";
        $hasil = mysql_query($query);
        $numrows = mysql_num_rows($hasil);
    }
    ?>
    
    <table cellpadding="10" cellspacing="2" align="center">
        <tr>
        <?php
            $kolom=3;
            $x = 0;
            if($numrows > 0)
            {
                while($data=mysql_fetch_array($hasil))
                {
                    if ($x >= $kolom) 
                    {
                        echo "</tr><tr>";
                        $x = 0;
                    }
            $x++;
        ?>
            <th>             
                <div id="title">
                    <a href="product.php?id=<?php echo $data['id']; ?>">
                    <?php echo $data['judul_barang']; ?>
                    </a>
                <br><br>
              </div>
    
              <div id="image">
                <a href="product.php?id=<?php echo $data['id']; ?>">
                    <img width='150' height='150' valign='top' border='1,5' src="product/<?php echo $data['gambar']; ?>" />
                </a>
                <br><br>
                </div>       
    
            <div id="action">
            <?php 
                echo '
                        <a href="product.php?id='.$data['id'].'">
                            <img src="images/detail.jpg"\ title="Detail Barang" border="0" width=\"50\" height=\"30\">
                        </a>';
                    ?>
                </div>
              <hr />    
            </th>
        <?php
            }
            }
        ?>
        </tr>
    </table>
    

0 个答案:

没有答案