为什么这个PHP脚本显示'网页不可用'

时间:2014-07-17 11:19:11

标签: php mysql

当我使用XAMPP服务器访问页面时,我不确定为什么以下简短的PHP脚本在Chrome中显示“网页不可用”。我将error_reporting设置为= E_ALL ^ E_DEPRECATED - 但是我没有收到任何错误。

我从来没有遇到过这个问题,在没有至少显示错误的情况下页面无法加载...

请参阅下面的代码:

PHP和MYSQL

$sql = "SELECT * from product WHERE brand_id NOT IN ('53', '10', '45', '29', '249')";
$result = mysql_query($sql) or die ( mysql_error() );

// load all stock
while ($line = mysql_fetch_assoc($result) )
{

// Contents of WHILE LOOP

// Size array to loop through when checking quantity
    $con_size = array (35,355,36,365,37,375,38,385,39,395,40,405,41,415,42,425,43,435,44,445,45,455,46,465,47,475,48,485);
    $arrayLength_uk=count($con_size);

        for($x=0;$x<$arrayLength_uk;$x++)
        {

        // check if size is available
        if($line['quantity_c_size_'.$con_size[$x].'_con_b'] > 0 )
        {

            $quantity = $line['quantity_c_size_'.$con_size[$x].'_con_b'];

            $sql = "UPDATE product
            SET quantity_c_size_$con_size[$x] = $quantity,
            quantity_c_size_$con_size[$x]_con_b = 0
            WHERE quantity_c_size_$con_size[$x]_con_b > 0";

            $result = mysql_query($sql);

            if ($result) 
            { 
               echo "Stock Updated"; 
            }
            else 
            { 
               echo "Something went wrong"; 
            }
        }
    }        
}

有人可以提供建议吗?谢谢。

解决

我解决了这个问题 - 这似乎是while($line = mysql_fetch_assoc($result) )的一个问题 - 我改为mysql_fetch_array

新代码

$sql = "SELECT * from product WHERE brand_id NOT IN ('53', '10', '45', '29', '249') AND active='on'";
$result = mysql_query($sql) or die ( mysql_error() );

// load all stock
while ($line = mysql_fetch_array($result))
{

    /*
     *  Continental Sizes
     * 
     */


    //Possible size array to loop through when checking quantity
    $con_size = array (35,355,36,365,37,375,38,385,39,395,40,405,41,415,42,425,43,435,44,445,45,455,46,465,47,475,48,485);
    $arrayLength_uk=count($con_size);

        for($x=0;$x<$arrayLength_uk;$x++)
        {

    // check if size is available
    if($line['quantity_c_size_'.$con_size[$x].'_chain'] > 0 )
    {

        $quantity = $line['quantity_c_size_'.$con_size[$x].'_chain'];
        $product_id = $line ['product_id'];

        echo $quantity; 

        $data = "UPDATE product
        SET quantity_c_size_$con_size[$x]_con_c = $quantity,
        quantity_c_size_$con_size[$x]_chain = 0
        WHERE product_id = '$product_id'";

        $result2 = mysql_query($data);

        if ($result2)
        {
            echo 'Stock Updated <br />';
        }
        else
        {
            echo 'Something went wrong <br />';
        }

        }
    }         
}

感谢所有回复的人。

1 个答案:

答案 0 :(得分:1)

问题是该行:

$result = mysql_query($sql);

您在内循环中更改$result变量,用于计算外循环中的迭代

你应该改变:

$result = mysql_query($sql);

            if ($result) 
            { 

$result2 = mysql_query($sql);

        if ($result2) 
        {