I am having the problem of extracting data row by row from a table build by html.
$result = mysql_query($query) or die("Unable to connecto to database.");
if(mysql_num_rows($result)){
$record = 0;
while($row = mysql_fetch_array($result,MYSQL_NUM)){
$record++;
$arrEmp[]= $row[0];
$arrName[] = $row[1];
$arrReason[] = $row[3];
$arrTimeStart[] = str_pad($row[4],2,"0",STR_PAD_LEFT). str_pad($row[5],2,"0",STR_PAD_LEFT);
$arrTimeEnd[] = str_pad($row[6],2,"0",STR_PAD_LEFT). str_pad($row[7],2,"0",STR_PAD_LEFT);
$arrDate[] = $row[9];
echo '<tr id="row'.$record.'" bgcolor="#FFFFD7" bordercolor="#FFFFD7">';
echo '<td id="clmEmpID'.$record.'"><font size="3">'.$row[0].'</font></td>';
echo '<td id="clmName'.$record.'"><font size="3">'.$row[1].'</font></td>';
echo '<td ><select name="OT_Rate" style="width:150px;">';
echo '<option selected>'.$row[2].'</option>';
$query3="SELECT * FROM otcode;";
$otcode=mysql_query($query3) or die("Unable to connect to db");
while($code=mysql_fetch_array($otcode,MYSQL_NUM)){
echo '<option><font size="3">'.$code[0].'</font></option>';
}
echo '</select></td>';
echo '<td id="clmReason'.$record.'"><font size="3">'.$row[3].'</font></td>';
echo '<td><input maxlength="4" name="TimeStart" type="text" size="3" value='. str_pad($row[4],2,"0",STR_PAD_LEFT). str_pad($row[5],2,"0",STR_PAD_LEFT).'><font size="3"></input></font></td>';
echo '<td><input maxlength="4" name="TimeEnd" type="text" size="3" value='. str_pad($row[6],2,"0",STR_PAD_LEFT). str_pad($row[7],2,"0",STR_PAD_LEFT).'><font size="3"></input></font></td>';
echo '<td><select name="Status" style="width: 100px;">';
echo '<option selected>'.$row[8].'</option>';
echo '<option>APPROVED</option>';
echo '<option>UNAPPROVED</option>';
echo '<option>NOT YET</option>';
echo '</select></td>';
echo '<td id="clmDate'.$record.'"><font size="3">'.$row[9].'</font></td>';
echo '</tr>';
$Date[]=$row[10];
$Emp[$record]=$row[0];
}
}
echo '</table>';
echo '<p></p>';
echo '<input type="submit" name="btnUpdate" id="btnUpdate" value="Update" style="BACKGROUND: #B1724B; BORDER-BOTTOM: #444444 2px solid; BORDER-LEFT: #444444 2px solid; BORDER-RIGHT: #444444 2px solid; BORDER-TOP: #444444 2px solid; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica;color:#FFFFFF;font-weight:bold;HEIGHT: 25px; WIDTH: 100px">';
if(isset($_POST['btnUpdate'])){
foreach($arrEmp as $key => $arrEmp){
/*for($i=0;$i<=$record;$i++){
$Emp = '<script type="text/javascript">document.getElementById(\'clmEmpID'.$i.'\').value</script>';
*/
$query5="UPDATE application,employee,supervisor SET application.OT_Rate='" . mysql_escape_string($_POST['OT_Rate']) . "',
application.Time_Start='" . mysql_escape_string($_POST['TimeStart']) . "', application.Time_End='" . mysql_escape_string($_POST['TimeEnd']). "',
application.ApplyStatus='" . mysql_escape_string($_POST['Status']) . "' WHERE application.Emp_ID='" . $arrEmp[$key] . "' AND application.Date_Apply='" . mysql_escape_string($Date[$key])."';";
echo '<p>'. $query5.'</p>';
mysql_query($query5);
}
}
Is there any problem with my array or code??This should really be in the PHP forum in "Server Side Programing", that's where you would get a quicker helpful response.
I'm sorry that I don't know much about Php.$arrEmp[$key]
that shouldn't be an array.
$result = mysql_query($query) or die("Unable to connecto to database.");
if(mysql_num_rows($result)){
$record = 0;
while($row = mysql_fetch_array($result,MYSQL_NUM)){
$record++;
$arrEmp[]= $row[0];
$arrName[] = $row[1];
$arrReason[] = $row[3];
$arrTimeStart[] = str_pad($row[4],2,"0",STR_PAD_LEFT). str_pad($row[5],2,"0",STR_PAD_LEFT);
$arrTimeEnd[] = str_pad($row[6],2,"0",STR_PAD_LEFT). str_pad($row[7],2,"0",STR_PAD_LEFT);
$arrDate[] = $row[9];
echo '<tr id="row'.$record.'" bgcolor="#FFFFD7" bordercolor="#FFFFD7">';
echo '<td id="clmEmpID'.$record.'"><font size="3">'.$row[0].'</font></td>';
echo '<td id="clmName'.$record.'"><font size="3">'.$row[1].'</font></td>';
echo '<td ><select name="OT_Rate" style="width:150px;">';
echo '<option selected>'.$row[2].'</option>';
$query3="SELECT * FROM otcode;";
$otcode=mysql_query($query3) or die("Unable to connect to db");
while($code=mysql_fetch_array($otcode,MYSQL_NUM)){
echo '<option><font size="3">'.$code[0].'</font></option>';
}
echo '</select></td>';
echo '<td id="clmReason'.$record.'"><font size="3">'.$row[3].'</font></td>';
echo '<td><input maxlength="4" name="TimeStart" type="text" size="3" value='. str_pad($row[4],2,"0",STR_PAD_LEFT). str_pad($row[5],2,"0",STR_PAD_LEFT).'><font size="3"></input></font></td>';
echo '<td><input maxlength="4" name="TimeEnd" type="text" size="3" value='. str_pad($row[6],2,"0",STR_PAD_LEFT). str_pad($row[7],2,"0",STR_PAD_LEFT).'><font size="3"></input></font></td>';
echo '<td><select name="Status" style="width: 100px;">';
echo '<option selected>'.$row[8].'</option>';
echo '<option>APPROVED</option>';
echo '<option>UNAPPROVED</option>';
echo '<option>NOT YET</option>';
echo '</select></td>';
echo '<td id="clmDate'.$record.'"><font size="3">'.$row[9].'</font></td>';
echo '</tr>';
$Date[]=$row[10];
$Emp[$record]=$row[0];
}
}
echo '</table>';
echo '<p></p>';
echo '<input type="submit" name="btnUpdate" id="btnUpdate" value="Update" style="BACKGROUND: #B1724B; BORDER-BOTTOM: #444444 2px solid; BORDER-LEFT: #444444 2px solid; BORDER-RIGHT: #444444 2px solid; BORDER-TOP: #444444 2px solid; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica;color:#FFFFFF;font-weight:bold;HEIGHT: 25px; WIDTH: 100px">';
if(isset($_POST['btnUpdate'])){
foreach($arrEmp as $key => $arrEmp){
/*for($i=0;$i<=$record;$i++){
$Emp = '<script type="text/javascript">document.getElementById(\'clmEmpID'.$i.'\').value</script>';
*/
$query5="UPDATE application,employee,supervisor SET application.OT_Rate='" . mysql_escape_string($_POST['OT_Rate']) . "',
application.Time_Start='" . mysql_escape_string($_POST['TimeStart']) . "', application.Time_End='" . mysql_escape_string($_POST['TimeEnd']). "',
application.ApplyStatus='" . mysql_escape_string($_POST['Status']) . "' WHERE application.Emp_ID='" . $arrEmp[$key] . "' AND application.Date_Apply='" . mysql_escape_string($Date[$key])."';";
echo '<p>'. $query5.'</p>';
mysql_query($query5);
}
}
Is there any problem with my array or code??This should really be in the PHP forum in "Server Side Programing", that's where you would get a quicker helpful response.
I'm sorry that I don't know much about Php.$arrEmp[$key]
that shouldn't be an array.