我是个新手。
我发现“将组合数据插入到MySQL中”有困难
示例:对于1、2、3、4,组合为:

123
124
134
234

我想把它插入到MySQL数据库中。
结果:
123
124
134
234
234 <= duplicate

我找不到问题所在。非常感谢。:-)
$lista = array($a,$b,$c,$d);
$b=1;

for ($i=0; $i<=3; $i++) {
  for ($j=$b; $j<=4;$j++) {
    for ($k=$j+1; $j<count($lista); $j++) {

       printf($lista[$i].','.$lista[$j].'<br>');

       $sql="INSERT INTO table10(id)
            VALUES($lista[$i]$lista[$j])";
        mysql_query( $sql, $con );

        }
    }
    $b++;
}

最佳答案

可以创建数组以避免重复数据

$dupList=array();
//declare this array before loop

//Hold  $lista[$i] and $lista[$j] jointly in a variable
$newVal=$lista[$i].$lista[$j];
if (!in_array($newVal, $dupList)) {

      $sql="INSERT INTO table10(id) VALUES ($newVal)";
      mysql_query( $sql, $con );
      array_push($dupList,$newVal);
}

关于php - PHP将组合插入MySQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27074838/

10-13 08:15