0

私はこの出席管理システムに取り組んでおり、特定の日付の出席を更新するフォームがあります。たとえば。今日の出席を変更する必要がある場合は、フォームを開いて出席をマークし、保存すると、出席がデータベースで更新されます。私はそれのためにfollowigコードをsed:

<?php

$dbhost = "localhost";
$dbuser = "root";
$dbname = "gail";

$conn = mysql_connect($dbhost, $dbuser,"") or die ('Error connecting to mysql');
mysql_select_db($dbname);
$cnt3 = count($_POST['pora']);

if ($cnt3 > 0 ) {
$updateArr = array();
$refArr = array();
for ($i=0; $i<$cnt3; $i++) 
{
    $updateArr[] = "('" . mysql_real_escape_string($_POST['pora'][$i]) . "')";
    $refArr[] = "('". mysql_real_escape_string($_POST['eid'][$i]) . "')";
}

$query = "update attendance set pora=" . implode(", ", $updateArr) . "where eid=" .     implode(", ", $refArr) ;
 mysql_query($query) or trigger_error("Insert failed: " . mysql_error());
}

mysql_close($conn);
?>

初めて出席を取るときは、複数の挿入に対して完全に機能します。しかし、同じ日の出席を更新するには機能しません。何か案は??

4

1 に答える 1

0

わかった!n all by mysef..見てください..乾杯:)

<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="gail"; // Database name 
$tbl_name="attendance"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Count table rows 
$count=mysql_num_rows($result);
?>
<center>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="test3.php">
<tr> 
<td>
<center>
<table width="500" border="1" bgcolor="orange" cellspacing="1" cellpadding="0">
 <tr>
  <td>&nbsp;</td>
  <td align="left"><label style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px;' for="eid" class="label" id="eid"><b> <i>Date </i> </b></label></td> 
  <td align="left"><label style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px;' for="eid" class="label" id="eid"><b> <i>Employee ID </i> </b> </label></td>
  <td align="left"> <label style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px;' for="ename" class="label" id="ename"><b> <i>Employee Name</i> </b></label></td>
  <td align="left"> <label style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px;' for="pora" class="label" id="pora"><b> <i>Attendance</i> </b></label></td>
  </font>
   <td>&nbsp;</td> 
</tr>   

 <?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td>&nbsp;</td>
<td align="center"><input style='color:black; font-family: Verdana; font-weight: bold;  font-size: 14px; background-color:orange; border-width: 0 0 0px 0; ' readonly name="dated[]" type="text" id="name" value="<?php echo $rows['dated']; ?>"></td>
<td align="center"><input style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px; background-color:orange; border-width: 0 0 0px 0; ' readonly name="eid[]" type="text" id="name" value="<?php echo $rows['eid']; ?>"></td>
<td align="center"><input style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px; background-color:orange; border-width: 0 0 0px 0; ' readonly  name="ename[]" type="text" id="lastname" value="<?php echo $rows['ename']; ?>"></td>
<td align="center"><select style='color:black; font-family: Verdana; font-weight: bold; font-size: 14px;' name="pora[]" id="pora">
<option> P </option>
<option> A </option>
<option> 0.5 </option>
<option> L </option>
<option> Lt </option>
</td>
</tr>
<?php
}
?>

<?php

$eid = $_POST['eid'];
$ename = $_POST['ename'];
$pora = $_POST['pora'];
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET pora='$pora[$i]' WHERE eid='$eid[$i]'";
$result1=mysql_query($sql1);
}

?>
于 2013-07-11T21:23:16.773 に答える