PHP多重插入和选择查询

时间:2017-08-31 18:00:26

标签: php mysql pdo

有人可以指出错误吗?我在没有循环的情况下运行,代码工作正常但是for循环没有执行,也没有显示错误..

if(isset( $_POST['name'], $_POST['samplecount'], $_POST['decks'])) 
{  

  $name = $_POST['name'];
  $sample = $_POST['samplecount'];
  $decks = $_POST['decks'];
  $rows = ($sample/$decks);

  for ($i=0; $i<$decks; $i++){

    for ($j=1; $j<=$rows; $j++) {

         $stmt = $dbconnect -> prepare(" INSERT INTO decks (id, dnumber, vtext) 

        ( SELECT :id, :dnumber, 

        (SELECT r.vtext FROM rsample r WHERE r.groupname = :groupname  AND r.vtext 

          NOT IN (SELECT vtext FROM decks) 

        ORDER BY rand() LIMIT :rows)

        )
    "); 

  $stmt -> bindValue(':id', $i);
  $stmt -> bindValue(':dnumber', $j);
  $stmt -> bindValue(':groupname',$name)
  $stmt -> bindValue(':rows', $rows);
  $stmt -> execute ();

    }
  }
}

在我的代码中,我使用name = "test"samplecount = 8decks = 2。因此$rows将是4

感谢。

0 个答案:

没有答案