我试图过滤各种自行车 女士们,男士们,孩子们。 我写了一个函数,它将我们的一串数字分类到选定类型的自行车。
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 . ",";
我做错了什么?
答案 0 :(得分:1)
有一种观察结果是,您引用了$totaal
和$total
,并且您返回的$amount1
不受$totaal
的影响。除非$totaal
是全局变量,否则不会使用它。
答案 1 :(得分:1)
我也注意到了这一点:
function bicycle($stringnumbers, $sortbicycle){
$bicycle = explode(',', $bicyclenumbers);
在您的函数中,输入是$ stringnumbers,但您不能在代码中的任何位置使用它。 相反,你使用$ bicylenumbers,shoudn" $ stringnumbers?