PHP代码阻止加载的网站内容

时间:2013-01-09 01:02:19

标签: php sql function block

我遇到以下代码问题。它只是阻止网站的其余部分加载,它没有完成预期的功能。

主PHP之前有一个JS,如下所示:

<script type="text/javascript">
    //http://jsbin.com/ujuse/1/edit
$(function() {
    $("input[type='checkbox']").on('change', function() {
        var boxes = [];
        // You could save a little time and space by doing this:
        var name = this.name;
        // critical change on next line
        $("input[type='checkbox'][name='"+this.name+"']:checked").each(function() {
            boxes.push(this.value);
        });
        if (boxes.length) {
            $(".loadingItems").fadeIn(300);
            // Change the name here as well
            $(".indexMain").load('store/indexMain.php?'+this.name+'=' + boxes.join("+"),
            function() {
                $(".indexMain").fadeIn('slow');
                $(".loadingItems").fadeOut(300);
            });

        } else {
            $(".loadingItems").fadeIn(300);
            $(".indexMain").load('store/indexMain.php', function() {
                $(".indexMain").fadeIn('slow');
                $(".loadingItems").fadeOut(300);
            });
        }
    });
});
</script>

<?php
function echoCheckboxSet($con, $header, $divClass, $columnName, $setName) {
$checkboxes = $con -> prepare("SELECT DISTINCT $columnName FROM item_descr ORDER BY $columnName ASC");
$checkboxes->execute();
?>
<div class="bgFilterTitles">
    <h1 class="filterTitles"><?php echo $header;?></h1>
</div>
<div class="<?php echo $divClass; ?>">
<?php
    while ($box = $checkboxes->fetch(PDO::FETCH_ASSOC)):
    $boxColumnName = str_replace('_',' ',$box[$columnName]);
?>
        <input type='checkbox' class='regularCheckbox' name='<?php echo $setName; ?>' value='<?php echo $box[$columnName]; ?>' />
        <font class='similarItemsText'><?php echo $boxColumnName; ?></font>
        <br />
<?php
endwhile;
?>
</div>
<?php
} // end of echoCheckboxSet

// Call our method twice, once for colors and once for prices
echoCheckBoxSet("COLOR", "colors", "color_base1", "color");
echoCheckBoxSet("PRICE", "prices", "price", "price");
?>

    Warning: Missing argument 5 for echoCheckboxSet(), called in 
\store\indexLeftBar.php on line 58 and defined in \store\indexLeftBar.php on line 35

    Fatal error: Call to a member function prepare() on a non-object in \store\indexLeftBar.php on line 36

你看到有什么问题吗?

谢谢!

1 个答案:

答案 0 :(得分:3)

使用

$con,但不在范围内:

function echoCheckboxSet($header, $divClass, $columnName, $setName) {
    $checkboxes = $con->....
}

将其作为参数(如下所示)传递给函数,或将其声明为global(不建议使用后者)。

function echoCheckboxSet($con, $header, $divClass, $columnName, $setName) {
    $checkboxes = $con->....
}

$con = some_method_that_connects_to_your_db(); // <!-- Still need this
echoCheckBoxSet( $con, "COLOR", "colors", "color_base1", "color");