Jquery Isotope กรองด้วยฐานข้อมูล

ฉันกำลังพยายามให้ปลั๊กอินไอโซโทปของ Metafizzy ทำงานได้ นี่คือการตั้งค่าที่ฉันมี ยกเว้นฉันกำลังดึงรายการคอนเทนเนอร์จากฐานข้อมูล sql - http://jsfiddle.net/trewknowledge/jJZEN/

ใครสามารถช่วยฉันหาสาเหตุที่มันไม่ทำงาน?

นี่คือรหัสที่ฉันใช้

จาวาสคริปต์

    //Load all items straight away
    $(document).ready(function(){  
        showEntries('*');
    });  

    //Isotope filter
    function filterEntries() {
        var $container = $('#entries');
           $select = $('#filters select');

        $container.isotope({
            itemSelector: '.item'
        });

        $select.change(function() {
            var filters = $(this).val();
            $('.active').removeClass('active');
            if (filters != '.item') {
                $( filters).addClass('active');
            }
            $container.isotope({
                filter: filters
            });
        });

    };


    //Pull in data from database
    function showEntries(str) {

        if (str=="") {
            document.getElementById("entries").innerHTML="";
            return;
        }
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest(); 
        }
        else {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {

                    document.getElementById("entries").innerHTML=xmlhttp.responseText;

                }
        }
            xmlhttp.open("POST","<?php bloginfo('template_url'); ?>/getentries.php?q="+str,true);
            xmlhttp.send();

            //Fire filter function
            filterEntries();
        }
</script>

HTML

<section id="filters">
      <select name="entries" onchange="showEntries(this.value)">
        <option value="*">show all</option>
        <option value=".item323" >323</option>
        <option value=".item266" >266</option>
        <option value=".item277" >277</option>
        <option value=".item289" >289</option>
      </select>
</section> <!-- #filters -->

<div id="entries" class="clearfix">

</div><!--entries-->

พีเอชพี

    $q=$_GET["q"];

    //Remove the '.item' before the cat id
    $q= ltrim ($q,'.item');

    $con = mysql_connect("localhost", "root", "root");
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("awards", $con);

    if ($q === "all" || $q === "*" ) {
        //Show all entries that have status registered if all is selected
        $sql="SELECT * FROM entry WHERE  status = 'registered'";
    } else {    
        //Else just show category entries of people who are registered
        $sql="SELECT * FROM entry WHERE awards_subcategory_id = '".$q."' && status = 'registered'";
    }
    $result = mysql_query($sql);


    while($row = mysql_fetch_array($result)) {

        print "<div class='item item$q'>";
        print '<img class="image" src="http://localhost:8888/awardsite/wp-content/themes/award/placeholder.jpg" />';
        print "<p class='studio'> Studio: " . $row['studio'] . "</p>";
        print "<p class='client'> Client: " . $row['client'] . "</p>";
        print "<p class='description'> Description: " . $row['description'] . "</p>";
        print "<p class='solutionprocess'> Solution Process: " . $row['solution_process'] . "</p>";
        print "</div>";

    }


    mysql_close($con);

person Allan    schedule 07.08.2012    source แหล่งที่มา
comment
อะไรไม่ทำงาน? คุณมีแซนด์บ็อกซ์หรือ jsfiddle ออนไลน์ที่ใคร ๆ ก็สามารถสัมผัสกับสิ่งที่ใช้งานไม่ได้ใช่ไหม ช่วยให้เราช่วยคุณ...   -  person Systembolaget    schedule 07.08.2012
comment
อันที่อยู่ใน jsfiddle ไม่ได้เชื่อมต่อกับฐานข้อมูล sql รายการที่ตัวกรองนั้นถูกฮาร์ดโค้ดใน html ไม่ใช่ไดนามิก ฉันแค่แสดงมันเป็นตัวอย่างของสิ่งที่ฉันต้องการบรรลุ ฉันรู้วิธีดำเนินการเมื่อประมาณ 20 นาทีที่แล้ว และจะโพสต์คำตอบเร็วๆ นี้   -  person Allan    schedule 07.08.2012
comment
ไชโย คงจะดีไม่น้อย ผู้อื่นอาจพบสิ่งผิดปกติในกรณีของคุณ   -  person Systembolaget    schedule 07.08.2012


คำตอบ (1)


จาวาสคริปต์

//Pull in data from database
    function showEntries() {
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            "use strict";
            xmlhttp=new XMLHttpRequest(); 
        }
        else {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState===4 && xmlhttp.status===200) {    
                document.getElementById("entries").innerHTML=xmlhttp.responseText;
                //Fire filter function once data loaded
                filterEntries();
            }
        }
        xmlhttp.open("POST","<?php bloginfo('template_url'); ?>/getentries.php?",true);
        xmlhttp.send();
    };

    //Load all items straight away
    showEntries('*');

    //Isotope filter
    function filterEntries() {
        var $container = $('#entries');
           $select = $('#filters select');

        $container.isotope({
            itemSelector : '.item',
            layoutMode : 'fitRows'
        });

        $select.change(function() {
            var filters = $(this).val();

            $container.isotope({
                filter: filters
            });
        });
    };

HTML

<section id="filters">
    <select name="entries"  onchange="filterEntries()">
        <option value="*">show all</option>
        <option value=".item323">323</option>
        <option value=".item266">266</option>
        <option value=".item277">277</option>
        <option value=".item289">289</option>
    </select>
</section> <!-- #filters -->

<div id="entries" class="clearfix">

</div><!--entries-->

พีเอชพี

$con = mysql_connect("localhost", "root", "root");
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("awards", $con);

    $sql="SELECT * FROM entry WHERE  status = 'registered'";

    $result = mysql_query($sql);


    while($row = mysql_fetch_array($result)) {
        //Get award cat ids
        $awardcat =  $row['awards_subcategory_id']  ;

        print "<div class='item item$awardcat'>";//add award cat id to each div
        print '<img class="image" src="http://localhost:8888/awardsite/wp-content/themes/award/placeholder.jpg" />';
        print "<p > Studio: " . $row['studio'] . "</p>";
        print "<p class='client'> Client: " . $row['client'] . "</p>";
        print "<p class='description'> Description: " . $row['description'] . "</p>";
        print "<p class='solutionprocess'> Solution Process: " . $row['solution_process'] . "</p>";
        print "</div>";

    }


    mysql_close($con);
person Allan    schedule 07.08.2012