 |
|
พอดีมีปัญหาอยู่ว่า
มีตารางข้อมูล ผู้ส่งมอบสินค้า มีฟิล ดังนี้ tran_id , tran_date ,employee_id
และตาราง emplyee มีฟิลล์ employee_id , employee_name
แต่ข้อมูลจะแสดง หน้าข้อมูล tran_id ,tran_date , employee_id( ตรงนี้จะเป็น ชื่อพนักงาน ) และเมื่อทำการ คลิก edit ชื่อที่เราต้องการเปลี่ยน
มันก็จะทำการยิงไปที่หน้า edit
แต่ ข้อมูล พนักงาน combo มันโชว์ออกมา แต่อยากให้มัน โชว์ชื่อ พนักงานที่เราที่เราเลือกมาน่ะ
แต่ที่เป็นอยู่มันจะโชว์อันแรกสุดเลย
อยากให้มันโชว์ชื่อพนักงานใน combo อันที่เราเลือกมาน่ะ
ช่วยด้วยครับ จากเด็กฝึกหัด
ด้านล่างเป็น code น่ะ
<?php require_once('../Connections/conn.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;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE tbl_transmitter_commits_product SET tran_date=%s, employee_id=%s WHERE tran_commit_product_id=%s",
GetSQLValueString($_POST['tran_date'], "date"),
GetSQLValueString($_POST['employee_id'], "int"),
GetSQLValueString($_POST['tran_commit_product_id'], "int"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());
$updateGoTo = "transmitter_commits_product_show.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_conn, $conn);
$query_rs_employee = "SELECT employee_id, employee_name FROM tbl_employee";
$rs_employee = mysql_query($query_rs_employee, $conn) or die(mysql_error());
$row_rs_employee = mysql_fetch_assoc($rs_employee);
$totalRows_rs_employee = mysql_num_rows($rs_employee);
mysql_select_db($database_conn, $conn);
$query_rs_tran = "SELECT * FROM tbl_transmitter_commits_product where tran_commit_product_id='$tran_commit_product_id'";
$rs_tran = mysql_query($query_rs_tran, $conn) or die(mysql_error());
$row_rs_tran = mysql_fetch_assoc($rs_tran);
$totalRows_rs_tran = mysql_num_rows($rs_tran);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="cal2.js"></script>
<script language="javascript" src="cal_conf2.js"></script>
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">รหัส :</td>
<td><?php echo $row_rs_tran['tran_commit_product_id']; ?></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">วันที่ :</td>
<td><input name="tran_date" type="text" id="tran_date" value="<?php echo $row_rs_tran['tran_date']; ?>" size="15" />
<small><a href="javascript:showCal('Calendar1')"><img src="../image/calendar.jpg" width="16" height="16" border="0" /></a></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">ชื่อพนักงาน :</td>
<td><label>
<select name="employee_id" id="employee_id">
<?php
do {
?>
<option value="<?php echo $row_rs_employee['employee_id']?>"<?php if (!(strcmp($row_rs_employee['employee_id'], $row_rs_tran['tran_commit_product_id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rs_employee['employee_name']?></option>
<?php
} while ($row_rs_employee = mysql_fetch_assoc($rs_employee));
$rows = mysql_num_rows($rs_employee);
if($rows > 0) {
mysql_data_seek($rs_employee, 0);
$row_rs_employee = mysql_fetch_assoc($rs_employee);
}
?>
</select>
</label></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Update record"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="tran_commit_product_id" value="<?php echo $row_rs_tran['tran_commit_product_id']; ?>">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($rs_employee);
mysql_free_result($rs_tran);
?>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
19 ก.ย. 2550 14:57:17 |
By :
Help me |
View :
1397 |
Reply :
0 |
|
 |
 |
 |
 |
|
|
|
 |