0

这是代码:

$sql = "SELECT * FROM blad1 order by RAND() LIMIT 6";
$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Vnaam = $row["Voornamen"]; 

$sql1 = "SELECT * FROM blad1 order by RAND() LIMIT 6";
$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Anaam = $row["Achternamen"]; 

$sql2 = "INSERT INTO duivengebruiker (Duif1) VALUES ('$Vnaam $Anaam')";
mysql_query($sql2);

$sql = "SELECT * FROM blad1 order by RAND() LIMIT 6";
$result=mysql_query($sql) ; 
$row=mysql_fetch_array($result);
$Vnaam = $row["Voornamen"]; 

$sql1 = "SELECT * FROM blad1 order by RAND() LIMIT 6";
$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Anaam = $row["Achternamen"]; 

$sql2 = "INSERT INTO duivengebruiker (Duif2) VALUES ('$Vnaam $Anaam')";
mysql_query($sql2);

这将创建 2 行并将第一个结果放在第一行的第一列中,并将第二个结果放在第二行的第二列中。我只想要两列都填满的 1 行。我该怎么做?大概是件容易的事。

4

1 回答 1

0

如果我理解正确,您想要做的是在执行插入之前选择两个随机名称。这样您就可以将它们都包含在一个查询中。例如,您可以尝试这样的事情:

$sql = "SELECT * FROM blad1 order by RAND() LIMIT 6";

$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Vnaam1 = $row["Voornamen"]; 

$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Anaam1 = $row["Achternamen"]; 

$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Vnaam2 = $row["Voornamen"]; 

$result = mysql_query($sql) ; 
$row = mysql_fetch_array($result);
$Anaam2 = $row["Achternamen"]; 

$insert_sql = "INSERT INTO duivengebruiker (Duif1, Duif2) VALUES ('$Vnaam1 $Anaam1','$Vnaam2 $Anaam2')";
mysql_query($insert_sql);
于 2012-09-22T17:44:49.737 回答