double0201 2017-04-06 06:13
浏览 45

类别按钮

I am trying to create a category button for my e-commerce website. Been trying to generate an idea of the button which clicked, so that the jQuery will be able to toggle the database which each represents. So far the idea is getting there but missing something.

So far all I have been doing is inputting the IDs statically and the outcome is grouping filter results, on top of each other instead of switching their results.

The database connection with SQL:

<?php
$db = mysqli_connect('127.0.0.1', 'root', '', 'firmciti');

if(mysqli_connect_errno()) {
    echo 'Database connect failed with follwing errors: '. mysqli_connect_error();
    die();
}
error_reporting();


$sql = "SELECT * FROM nav";
$squery = $db->query($sql);
$pql = "SELECT * FROM companies";
$pquery = $db->query($pql);
$gql = "SELECT * FROM companies WHERE catId = 2";
$gquery = $db->query($gql);
$fql = "SELECT * FROM companies WHERE catId = 3";
$fquery = $db->query($fql);
$aql = "SELECT * FROM companies WHERE catId = 4";
$aquery = $db->query($aql);
$cql = "SELECT * FROM companies WHERE catId = 5";
$cquery = $db->query($cql);
...
?>

The jquery:

<script>
$(document).ready(function(){
    $("#1").click(function(){
        $("#view").toggle();

    });
});
$(document).ready(function(){
    $("#2").click(function(){
        $("#view1").toggle();

    });
});
$(document).ready(function(){
    $("#3").click(function(){
        $("#view2").toggle();

    });
});
$(document).ready(function(){
    $("#4").click(function(){
        $("#view3").toggle();

    });
...</script>

The html:

<?php while($cat = mysqli_fetch_assoc($squery)): ?> 
<button id="<?=$cat['catId']; ?>"><img src="<?=$cat['img'];?>" style="height: 80px; width: 80px; margin: 0 15px;"/> </button>

<?php endwhile; ?>

<!--all-->

<div id="view" style="margin: 0 20px" >

<?php while($comp = mysqli_fetch_assoc($pquery)): ?> 
<!-- Gallery list-->
    <button class="w3-button w3-white w3-border w3-hover-amber " href="" type="button" style="width: 340px; height: 100px; margin: 5px;"><div class="col-xs-4">
        <img src="<?=$comp['compLogo'];?>" style="height: 80px; width: 80px";/>
            </div>
        <div class="col-xs-8">
            <h4 class="w3-display-topleft"><?=$comp['compName'];?></h4><br><br>


            <h6 class="w3-half">25min</h6>

        </div>
    </button>

<?php endwhile;?>
</div>


<!--grocery-->
<div id="view1" style="margin: 0 20px" hidden="">

<?php while($comp = mysqli_fetch_assoc($gquery)): ?> 
<!-- Gallery list-->
    <button class="w3-button w3-white w3-border w3-hover-amber " href="" type="button" style="width: 340px; height: 100px; margin: 5px;"><div class="col-xs-4">
        <img src="<?=$comp['compLogo'];?>" style="height: 80px; width: 80px";/>
            </div>
        <div class="col-xs-8">
            <h4 class="w3-display-topleft"><?=$comp['compName'];?></h4><br><br>


            <h6 class="w3-half">25min</h6>

        </div>
    </button>

<?php endwhile;?>
</div>

<!--food-->
<div id="view2" style="margin: 0 20px" hidden="">

<?php while($comp = mysqli_fetch_assoc($fquery)): ?> 
<!-- Gallery list-->
    <button class="w3-button w3-white w3-border w3-hover-amber " href="" type="button" style="width: 340px; height: 100px; margin: 5px;"><div class="col-xs-4">
        <img src="<?=$comp['compLogo'];?>" style="height: 80px; width: 80px";/>
            </div>
        <div class="col-xs-8">
            <h4 class="w3-display-topleft"><?=$comp['compName'];?></h4><br><br>


            <h6 class="w3-half">25min</h6>

        </div>
    </button>

<?php endwhile;?>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端