|
 |
|
ติดปัญหา update database (ไม่ ทราบวิธีเอาข้อมูลเข้าจากการวนloopของ table) |
|
 |
|
|
 |
 |
|
ผมต้องการที่จะ input ข้อมูลที่ได้จาก code ข้างล่างนี้ต้องทำอย่างไร
โดยข้อมูล 1set ประกอบด้วย วันเดือนปี 1วัน ,tct_id 1user,shift_id (insert ข้อมูลที่ table "time_stamp_user_detail")
Table มี
tct_user --> มี tct_id ,name ,f_name
project_detail --> มี pro_id,pro_name
time_stamp_user_detail --> มี tct_id ,date_shift ,shift_id
Code อาจจะดูยากนิดนึงครับ ผมพยายามเขาจากความรู้ที่มีนะ
----------------------------------------------------------------------------------------------------------------------------------
<? include("inc\DB_Conf.php");?>
<!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" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<select name="name_list" onChange="document.getElementById('name').value=this.value; ">
<? $sql_select= "SELECT * FROM project_shift";
$result_show = mysql_db_query($dbname,$sql_select);
while ($row = mysql_fetch_array($result_show)){;
?>
<option value="<?=$row[shift_id]?>"><?=$row[shift_name]?></option><? } ?>
</select>
<input type="text" name="name" id="name" >
</form>
<p>
<form id="form2" name="form2" method="post" action="create_shift.php">
<?
$this_month =date('21-m-Y');
$next_month =date('20-m-Y',strtotime('+1 month'));
$tag_date = (strtotime($next_month)-strtotime($this_month))/ ( 60 * 60 * 24 );
?>
<table border="1">
<tr>
<td ><input name="dates" type="text" value="<? echo $tag_date ?>" /></td>
<?
$n=0;
while($n <=$tag_date) {
?>
<td >
<? echo date("D", strtotime("+ $n day", strtotime($this_month)))?>
</td>
<?
$n++;}
?>
</tr>
<tr>
<td> </td>
<?
$n=0;
while($n <=$tag_date) {
?>
<? $shift_date=date("d", strtotime("+ $n day", strtotime($this_month)))?>
<td><? echo $shift_date?></td>
<?
$n++;}
?>
</tr>
<? $i=0;?>
<?
//ดึง user มาแสดง
$sql_select_name= "SELECT * FROM tct_user INNER JOIN project_detail ON tct_user.pro_id = project_detail.pro_id";
$result_sql_show = mysql_db_query($dbname,$sql_select_name);
while ($row_show = mysql_fetch_array($result_sql_show)){
//สร้าง BG
$i++;
if($i%2==0)
{
$bg = "#F0FFF0";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td height="26"><? echo $row_show['name']." "." ".$row_show['f_name']."<br>";?><input name="tct_id" type="text" value="<? echo $row_show['tct_id']?>" /></td>
<?
$n=0;
while($n <=$tag_date) {;
?>
<td><select name="name_list" onfocus="this.value=document.getElementById('name').value;return true;">
<option value="★">★</option>
<? $sql_select= "SELECT * FROM project_shift";
$result_show = mysql_db_query($dbname,$sql_select);
while ($row = mysql_fetch_array($result_show)){;
?>
<option value="<?=$row[shift_id]?>"><?=$row[shift_name]?></option><? } ?>
</select>
</td>
<?
$n++;}
?>
</tr>
<? }?>
</table>
<p>
<input type="submit" name="submit" id="submit" value="Submit" /><input type="reset" name="clear" id="clear" value="Reset" />
</p>
</form>
<p>
</body>
</html>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-07-01 10:02:37 |
By :
ziix |
View :
1409 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่านซะหน่อยไม่เสียหลาย
Code (PHP)
<? include("inc\DB_Conf.php");?>
<!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" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<select name="name_list" onChange="document.getElementById('name').value=this.value; ">
<? $sql_select= "SELECT * FROM project_shift";
$result_show = mysql_db_query($dbname,$sql_select);
while ($row = mysql_fetch_array($result_show)){;
?>
<option value="<?=$row[shift_id]?>"><?=$row[shift_name]?></option><? } ?>
</select>
<input type="text" name="name" id="name" >
</form>
<p>
<form id="form2" name="form2" method="post" action="create_shift.php">
<?
$this_month =date('21-m-Y');
$next_month =date('20-m-Y',strtotime('+1 month'));
$tag_date = (strtotime($next_month)-strtotime($this_month))/ ( 60 * 60 * 24 );
?>
<table border="1">
<tr>
<td ><input name="dates" type="text" value="<? echo $tag_date ?>" /></td>
<?
$n=0;
while($n <=$tag_date) {
?>
<td >
<? echo date("D", strtotime("+ $n day", strtotime($this_month)))?>
</td>
<?
$n++;}
?>
</tr>
<tr>
<td> </td>
<?
$n=0;
while($n <=$tag_date) {
?>
<? $shift_date=date("d", strtotime("+ $n day", strtotime($this_month)))?>
<td><? echo $shift_date?></td>
<?
$n++;}
?>
</tr>
<? $i=0;?>
<?
//ดึง user มาแสดง
$sql_select_name= "SELECT * FROM tct_user INNER JOIN project_detail ON tct_user.pro_id = project_detail.pro_id";
$result_sql_show = mysql_db_query($dbname,$sql_select_name);
while ($row_show = mysql_fetch_array($result_sql_show)){
//สร้าง BG
$i++;
if($i%2==0)
{
$bg = "#F0FFF0";
}
else
{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<?=$bg;?>">
<td height="26"><? echo $row_show['name']." "." ".$row_show['f_name']."<br>";?><input name="tct_id" type="text" value="<? echo $row_show['tct_id']?>" /></td>
<?
$n=0;
while($n <=$tag_date) {;
?>
<td><select name="name_list" onfocus="this.value=document.getElementById('name').value;return true;">
<option value="★">★</option>
<? $sql_select= "SELECT * FROM project_shift";
$result_show = mysql_db_query($dbname,$sql_select);
while ($row = mysql_fetch_array($result_show)){;
?>
<option value="<?=$row[shift_id]?>"><?=$row[shift_name]?></option><? } ?>
</select>
</td>
<?
$n++;}
?>
</tr>
<? }?>
</table>
<p>
<input type="submit" name="submit" id="submit" value="Submit" /><input type="reset" name="clear" id="clear" value="Reset" />
</p>
</form>
<p>
</body>
</html>
|
 |
 |
 |
 |
Date :
2010-07-01 10:31:34 |
By :
oxygenyoyo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
???ไม่เข้าใจครับ ว่าOxyGenyoyoหมายถึงอะไร เพราะ code นี้ผมเขียนเอง
ปัญหาที่เจอคือ ไม่รู้จะเอาข้อมูลลง DB อย่างไรเพราะไป echo ดูที่ create_shift.php มันออกแต่ค่าสุดท้าย
รบกวน คุณOxyGenyoyo แนะนำด้วยครับ
|
 |
 |
 |
 |
Date :
2010-07-01 11:04:51 |
By :
ziix |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอจะมีตัวอย่างใหมครับ
การใช้ SQL command ผมทำได้อยู่
post and get ก็พอได้ เคยทำแต่ post /get ที่ตัวแปลชื่อไม่เหมือนกันแต่อันนี้มันชื่อเดียวกันเลยแต่มีค่าไม่เหมือนกัน

ex
ชื่อ เอามาจาก tableใน db นึง(สมมุติชื่อtable name)
วันที่ คำนวนเอา
ค่าจาก dropdown เอามาจาก tableใน db นึงให้เลือกค่าที่ต้องการในช่องนั้นๆ(สมมุติชื่อtable list)
เอาทั้งหมด insertลง db ใหม่(สมมุติชื่อtable shift)
ใน insert command 1set ให้มี ชื่อ วัน และ ค่าจาก dropdown list
|
 |
 |
 |
 |
Date :
2010-07-01 11:54:05 |
By :
ziix |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งงครับ จะส่งค่า ผ่านตัวแปรชื่อเดียวกันได้ไง มันต้องส่งคนละชื่อสิครับ
ถ้าส่งตัวแปรชื่อเดียวกันคงต้องนำค่ามาต่อกัน เวลารับก็เขียนคำสั่งแยกละมั้ง เหอะๆ
หรือผมเข้าใจอะไรผิดอีกไหมเนี่ย
|
 |
 |
 |
 |
Date :
2010-07-01 13:13:56 |
By :
50121680 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|