我想在一个表中插入自动数据..一个数据将来自另一个我在这里称为 p_no(personal number) 的表,它来自另一个表(emp_info) n 它是另一个表出勤的外键。我想自动插入 1200 个数据,只需单击一个按钮 .1200 数据意味着 1200 p_no 和其他信息。
1.emp_info(p_no,name,designation..etc) P_no 是主键 2.attandance (aid(auto increment),attendance,tiffin,shift,ot date,p_no) p_no 是外键。现在我想通过单击一个按钮从 emp_info 表中访问 p_no 信息来自动插入 1200 个数据。
我正在使用dreamweaver、php、mysql。
<?php require_once('Connections/bndock.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
mysql_select_db($database_bndock, $bndock);
$query_Recordset1 = "SELECT p_no FROM emp_info";
$Recordset1 = mysql_query($query_Recordset1, $bndock) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$val=10;
for($row_Recordset1=0;$row_Recordset1<=$val;$row_Recordset1++){
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO attndance (aid, doa, attnc, stnd, ot, shift, p_no) VALUES (%s, now(), %s, %s, %s, %s,%s)",
GetSQLValueString($_POST['aid'], "int"),
GetSQLValueString($_POST['attnc'], "text"),//attendance//doa=date
GetSQLValueString($_POST['stnd'], "text"),//tiffin
GetSQLValueString($_POST['ot'], "text"),
GetSQLValueString($_POST['shift'], "text"),
GetSQLValueString($_POST['p_no'], "int"));
mysql_select_db($database_bndock, $bndock);
$Result1 = mysql_query($insertSQL, $bndock) or die(mysql_error());
$insertGoTo = "attnd_show.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
}
?>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="296" height="190" align="center" bordercolor="#ECE9D8" bgcolor="#ECE9D8">
<tr valign="baseline">
<td colspan="2" align="right" nowrap="nowrap"> </td>
</tr>
<tr valign="baseline">
<td width="77" align="right" nowrap="nowrap"><strong>Attendance:</strong></td>
<td width="193"><select name="attnc">
<option value="P" selected="selected">P</option>
<option value="A">A</option>
<option value="L">L</option>
<option value="Sick">Sick</option>
<option value="Suspend">Suspend</option>
<option value="TY">TY</option>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Stand Easy :</strong></td>
<td><select name="stnd">
<option value="Yes">Y</option>
<option value="No">N</option>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Over time:</strong></td>
<td><select name="ot">
<option value="Yes">Y</option>
<option value="No">N</option>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>Shift:</strong></td>
<td><select name="shift">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option selected="selected">-</option>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"><strong>P.No:</strong></td>
<td><select name="p_no">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['p_no']?>" <?php if (!(strcmp($row_Recordset1['p_no'], $row_Recordset1['p_no']))) {echo "SELECTED";} ?>><?php echo $row_Recordset1['p_no']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
?>
</select> </td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input name="submit" type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="aid" value="" />
<input type="hidden" name="MM_insert" value="form1" />
</form></td>