0

为什么不输出第一个元素数组?

我使用下一个代码

$product_idn='123112$2313213';
$count_products=substr_count($product_idn,'$')+1;

$idn_products=explode('$',$product_idn);
$name_products='';
$s=0;
while($s<=$count_products){
$prod=$idn_products[$s];
$res10=mysql_query("..... WHERE `product_idn`='$prod'");
$i10=mysql_fetch_assoc($res10);
$name_products.=$i10['name'].', ';
$s++;
}
echo $name_products;
//give 2313213,,

为什么不输出第一个元素数组?

4

2 回答 2

4

关于什么

$product_idn='123112$2313213';

$idn_products=explode('$',$product_idn);
$name_products='';

foreach($idn_products as $val){
$res10=mysql_query("..... WHERE `product_idn`='$val'");
$i10=mysql_fetch_assoc($res10);
$name_products.=$i10['name'].', ';
}
echo $name_products;
于 2012-12-04T22:07:24.300 回答
0

原始代码中使用了许多不寻常的技术。在不知道这段代码的目的的情况下,我最好的猜测是:

$product_idn = '123112$2313213';

$idn_products = explode('$', $product_idn);

$name_products = '';
foreach($product_idn as $value) {
    $res10 = mysql_query("SELECT name FROM ... WHERE `product_idn`='$value'");
    if ($res10) {
        $i10 = mysql_fetch_assoc($res10);
        $name_products .= $i10['name'].', ';
    }
}
$name_products = rtrim(', ', $name_products);
echo $name_products;
于 2012-12-04T22:14:13.987 回答