0

我试图过滤各种自行车女士、男士、儿童。我写了一个函数,将我们的一串数字排序为所选类型的自行车。

function: bicycle($stringnumbers, $sortbicycle)

脚本:

    function bicycle($stringnumbers, $sortbicycle){
    $bicycle = explode(',', $bicyclenumbers);
    foreach($bicycle as $bicycle1)
    {
       $sql2 = "SELECT * FROM `bicycle` WHERE `bicyclenumber` LIKE '".$bicycle1."' LIMIT 0, 30 ";
       $number = mysql_query($sql2)or die(mysql_error());
       while ($bicycleinfo = mysql_fetch_array($number)) 
       {
          $number1 = $bicycleinfo['sortbicycle'];
          if($sortbicycle == "kid") 
          {
             if($number1 == "boy")
             {
                $totaal .= "J " . $bicycle1 . ",";
             }
             elseif($number1 == "girl")
             {
                $totaal .= "M " . $bicycle1 . ",";
             }      
          }
          elseif($sortbicycle == "kids") 
          {
             if ($number1 == "boy")
             {
                $totaal .= $bicycle1 . ",";
             }
             elseif($number1 == "girl")
             {
                $totaal .= $bicycle1 . ",";
             }      
          }
          elseif($number1 == $sortbicycle)
          {
             $totaal .= $bicycle1 . ",";
          }
       }
    }

    if($totaal > "1")
    {
       $amount1 = $total;
    }
    else
    {
       $amount1 = ""; 
    }

 return $amount1;   
 }

但由于某种原因,这部分:

    if ($number1 == "boy")
    {
       $totaal .= "J " . $bicycle1 . ",";
    }
    elseif ($number1 == "girl")
    {
       $totaal .= "M " . $bicycle1 . ",";
    }               
 }
 elseif ($sortbicycle == "kids") 
 {
    if ($number1 == "boy")
    {
       $totaal .= $bicycle1 . ",";
    }
    elseif ($number1 == "girl")
    {
       $totaal .= $bicycle1 . ",";
    }           
 }

没有按应有的方式工作,第一部分“孩子”部分有效,但是当我删除

$totaal .= "J " . $bicycle1 . ",";

$totaal .= $bicycle1 . ",";

我究竟做错了什么?

4

2 回答 2

1

我也注意到了这一点:

function bicycle($stringnumbers, $sortbicycle){
$bicycle = explode(',', $bicyclenumbers);

在您的函数中,输入是 $stringnumbers 但您不在代码中的任何地方使用它。相反,您使用 $bicylenumbers,不应该是 $stringnumbers 吗?

于 2012-07-04T18:00:17.803 回答
1

一个观察结果是,您同时引用了$totaaland $total,并且您返回$amount1的结果绝不会受到 的影响$totaal。除非$totaal是全局变量,否则不会使用。

于 2012-07-04T17:04:41.377 回答