  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                คือผมทำโปรเจคเกี่ยวกับการสร้างตารางสอนครับ 
โดยมี table ดังนี้ 
classroom 
  id, name, seat, m_cou1(วันจันทร์ วิชาที่1), m_cou2(วันจันทร์ วิชาที่2), ... f_tea10(วันศุกร์ วิชาที่10); 
course 
  id, cou_name; 
student 
  id, name, num,  m_cou1(วันจันทร์ วิชาที่1), m_cou2(วันจันทร์ วิชาที่2), ... f_tea10(วันศุกร์ อาจารย์ที่สอนคาบที่10); 
teacher 
  id , name, m_cou1(วันจันทร์ วิชาที่1), m_cou2(วันจันทร์ วิชาที่2), ... f_tea10(วันศุกร์ อาจารย์ที่สอนคาบที่10); 
 
โดยคอนเซปของผมคือ ให้ไปเลือกข้อมูลจาก student มาแสดง เป็น listmenu ว่าจะทำการสร้างตารางสอนของ นศ.ชั้นไหน 
โดยเมือเลือกแล้ว ส่งค่า $stu ไปเพื่อใช้ในการ select ข้อมูล ของ นศ.ชั้นนั้นๆมาแสดง (อันนี้ทำได้แล้ว) 
 
ปัญหาอยู่ตรงที่ เมื่อต้องการ อัพเดท ข้อมูลต่างๆ สมมติ ผมเลือก ปวช.1/1 วันจันทร์ คาบแรก วิชา (ผมกำหนดเป็น m_cou1) 
ให้ลิงค์ไปที่ หน้า add.php เพื่อเลือกวิชา แล้ว นำมาอัพเดท มันอัพเดทไม่ได้อ่ะ ครับ คาดว่าจะติดตรงที่ โค้ด update ดูหลายตัวอย่างแล้วแต่ยังไม่เข้าใจ ช่วยแนะนำหน่อยนะครับ 
 
create_ctt.php Code (PHP) 
<?php 
include("conn.php");
include("header.php");
?>
<form id="form1" name="form1" method="get" action="create.php">
  <h3>สรางตารางสอน  </h3>
  <table width="241" border="0" cellspacing="0" bgcolor="#F0F0F0">
    <tr>
      <td colspan="2">โรงเรียน สยามธุรกิจ ในพระอุปถัมภ์ฯ </td>
    </tr>
    <tr>
      <td width="140">ภาคเรียนที่</td>
      <td width="544"> </td>
    </tr>
    <tr>
      <td>นศ.ห้อง</td>
      <td><select name="student" id="student" onchange="MM_jumpMenu('parent',this,0)">
                  <?php
		$result = mysql_query("SELECT * FROM student;");
		while($data = mysql_fetch_array($result)){
		echo "<option values='{$data['name']}'>{$data['name']}</option>";
		}
		?>
      </select>
	  <input name="name" type="hidden" id="name" value="name" /></td>
    </tr>
    <tr>
      <td>ที่ปรึกษา</td>
      <td>
      <select name="teacher" id="teacher" onchange="MM_jumpMenu('parent',this,0)">
        <?php
		$result = mysql_query("SELECT * FROM teacher;");
		while($data = mysql_fetch_array($result)){
		echo "<option values='{$data['name']}'>{$data['name']}</option>";
		}
		?>
      </select>    </td>
    </tr>
    <tr>
      <td> </td>
      <td><label>
        <input type="submit" name="Submit" value="สร้าง" />
      </label></td>
    </tr>
  </table>
</form>
 
 
create.php Code (PHP) 
<?php
include("conn.php");
include("header.php");
$stu = $_GET[student];
$tea = $_GET[teacher];
if($_GET){
	$sql = "SELECT * FROM student WHERE name = '$stu';";	
	$result = mysql_query($sql);
if(!$result){
	echo "เกิดข้อผิดพลาดในการเข้าถึงตาราง<br>";
}
else {
	echo "<a href=create_ctt.php>กลับ</a>";
	echo "<table width=100% border=0>";
	echo "<tr><th align=center>";
	echo "ตารางสอนโรงเรียน สยามธุรกิจในพระอุปถัมภ์<br>";
	echo "ห้อง" . $stu . "<br>";
	echo "ที่ปรึกษา" . $tea . "<br>";
	echo "<table width=1000 border=1>";
	echo "<tr>
	<th align=center valign=top>เวลา</th>
      <th align=center valign=top>08.30-09.20</th>
      <th align=center valign=top>09.20-10.10</th>
      <th align=center valign=top>10.20-11.10</th>
      <th align=center valign=top>11.10-12.00</th>
      <th align=center valign=top>12.00-12.50</th>
      <th align=center valign=top>13.00-13.50</th>
      <th align=center valign=top>13.50-14.40</th>
      <th align=center valign=top>14.40-15.30</th>
      <th align=center valign=top>15.30-16.20</th>
      <th align=center valign=top>16.20-14.10</th>
	  </tr>";
	echo "<tr>
      <th align=center valign=top>วัน</th>
      <th align=center valign=top>คาบที่ 1 </th>
      <th align=center valign=top>คาบที่ 2 </th>
      <th align=center valign=top>คาบที่ 3 </th>
      <th align=center valign=top>คาบที่ 4 </th>
      <th align=center valign=top>คาบที่ 5 </th>
      <th align=center valign=top>คาบที่ 6 </th>
      <th align=center valign=top>คาบที่ 7 </th>
      <th align=center valign=top>คาบที่ 8 </th>
      <th align=center valign=top>คาบที่ 9 </th>
      <th align=center valign=top>คาบที่ 10 </th>
    </tr>";
	
	while($data = mysql_fetch_array($result)){
	echo "<tr><th>จันทร์</th>
	<th>{$data['m_cou1']}<a href=add.php?add=m_cou1&name={$data['name']}>e</a><br>
	{$data['m_cla1']}<a href=add.php?id={$data['m_cla1']}>e</a><br>
	{$data['m_tea1']}<a href=add.php?id={$data['m_tea1']}>e</a></th>
	
	<th>{$data['m_cou2']}<br>{$data['m_cla2']}<br>{$data['m_tea2']}</th>
	<th>{$data['m_cou3']}<br>{$data['m_cla3']}<br>{$data['m_tea3']}</th>
	<th>{$data['m_cou4']}<br>{$data['m_cla4']}<br>{$data['m_tea4']}</th>
	<th>{$data['m_cou5']}<br>{$data['m_cla5']}<br>{$data['m_tea5']}</th>
	<th>{$data['m_cou6']}<br>{$data['m_cla6']}<br>{$data['m_tea6']}</th>
	<th>{$data['m_cou7']}<br>{$data['m_cla7']}<br>{$data['m_tea7']}</th>
	<th>{$data['m_cou8']}<br>{$data['m_cla8']}<br>{$data['m_tea8']}</th>
	<th>{$data['m_cou9']}<br>{$data['m_cla9']}<br>{$data['m_tea9']}</th>
	<th>{$data['m_cou10']}<br>{$data['m_cla10']}<br>{$data['m_tea10']}</th></tr>
	
	<tr><th>อังคาร</th>
	<th>{$data['t_cou1']}<br>{$data['t_cla1']}<br>{$data['t_tea1']}</th>
	<th>{$data['t_cou2']}<br>{$data['t_cla2']}<br>{$data['t_tea2']}</th>
	<th>{$data['t_cou3']}<br>{$data['t_cla3']}<br>{$data['t_tea3']}</th>
	<th>{$data['t_cou4']}<br>{$data['t_cla4']}<br>{$data['t_tea4']}</th>
	<th>{$data['t_cou5']}<br>{$data['t_cla5']}<br>{$data['t_tea5']}</th>
	<th>{$data['t_cou6']}<br>{$data['t_cla6']}<br>{$data['t_tea6']}</th>
	<th>{$data['t_cou7']}<br>{$data['t_cla7']}<br>{$data['t_tea7']}</th>
	<th>{$data['t_cou8']}<br>{$data['t_cla8']}<br>{$data['t_tea8']}</th>
	<th>{$data['t_cou9']}<br>{$data['t_cla9']}<br>{$data['t_tea9']}</th>
	<th>{$data['t_cou10']}<br>{$data['t_cla10']}<br>{$data['t_tea10']}</th>
	</tr>
	
	<tr><th>พุธ</th>
	<th>{$data['w_cou1']}<br>{$data['w_cla1']}<br>{$data['w_tea1']}</th>
	<th>{$data['w_cou2']}<br>{$data['w_cla2']}<br>{$data['w_tea2']}</th>
	<th>{$data['w_cou3']}<br>{$data['w_cla3']}<br>{$data['w_tea3']}</th>
	<th>{$data['w_cou4']}<br>{$data['w_cla4']}<br>{$data['w_tea4']}</th>
	<th>{$data['w_cou5']}<br>{$data['w_cla5']}<br>{$data['w_tea5']}</th>
	<th>{$data['w_cou6']}<br>{$data['w_cla6']}<br>{$data['w_tea6']}</th>
	<th>{$data['w_cou7']}<br>{$data['w_cla7']}<br>{$data['w_tea7']}</th>
	<th>{$data['w_cou8']}<br>{$data['w_cla8']}<br>{$data['w_tea8']}</th>
	<th>{$data['w_cou9']}<br>{$data['w_cla9']}<br>{$data['w_tea9']}</th>
	<th>{$data['w_cou10']}<br>{$data['w_cla10']}<br>{$data['w_tea10']}</th>
	
	<tr><th>พฤหัสบดี</th>
	<th>{$data['th_cou1']}<br>{$data['th_cla1']}<br>{$data['th_tea1']}</th>
	<th>{$data['th_cou2']}<br>{$data['th_cla2']}<br>{$data['th_tea2']}</th>
	<th>{$data['th_cou3']}<br>{$data['th_cla3']}<br>{$data['th_tea3']}</th>
	<th>{$data['th_cou4']}<br>{$data['th_cla4']}<br>{$data['th_tea4']}</th>
	<th>{$data['th_cou5']}<br>{$data['th_cla5']}<br>{$data['th_tea5']}</th>
	<th>{$data['th_cou6']}<br>{$data['th_cla6']}<br>{$data['th_tea6']}</th>
	<th>{$data['th_cou7']}<br>{$data['th_cla7']}<br>{$data['th_tea7']}</th>
	<th>{$data['th_cou8']}<br>{$data['th_cla8']}<br>{$data['th_tea8']}</th>
	<th>{$data['th_cou9']}<br>{$data['th_cla9']}<br>{$data['th_tea9']}</th>
	<th>{$data['th_cou10']}<br>{$data['th_cla10']}<br>{$data['th_tea10']}</th>
	
	<tr><th>ศุกร์</th>
	<th>{$data['f_cou1']}<br>{$data['f_cla1']}<br>{$data['f_tea1']}</th>
	<th>{$data['f_cou2']}<br>{$data['f_cla2']}<br>{$data['f_tea2']}</th>
	<th>{$data['f_cou3']}<br>{$data['f_cla3']}<br>{$data['f_tea3']}</th>
	<th>{$data['f_cou4']}<br>{$data['f_cla4']}<br>{$data['f_tea4']}</th>
	<th>{$data['f_cou5']}<br>{$data['f_cla5']}<br>{$data['f_tea5']}</th>
	<th>{$data['f_cou6']}<br>{$data['f_cla6']}<br>{$data['f_tea6']}</th>
	<th>{$data['f_cou7']}<br>{$data['f_cla7']}<br>{$data['f_tea7']}</th>
	<th>{$data['f_cou8']}<br>{$data['f_cla8']}<br>{$data['f_tea8']}</th>
	<th>{$data['f_cou9']}<br>{$data['f_cla9']}<br>{$data['f_tea9']}</th>
	<th>{$data['f_cou10']}<br>{$data['f_cla10']}<br>{$data['f_tea10']}</th>
	</tr>
	";	}
}	
}
?>
 
 
 
add.php Code (PHP) 
<?php 
include("conn.php");
include("create_tb.php");
$stu = $_GET[student];
$tea = $_GET[teacher];
$name = $_GET[name];
if($_GET){
	$sql = "SELECT * FROM student WHERE name = '$name';";	
	mysql_query($sql) or die("cannot select");
}
if($_POST){
	$sql = "UPDATE student SET m_cou1 = {$data['cou_name']} WHERE name = $name, m_cou1;";
	$qry = mysql_query($sql);
	if(!$qry){
		echo "cannot post<br>
		<a href=create_ctt.php>back</a>";
	}
	else{
		echo "complete<br>
		<a href=create_ctt.php>back</a>";
	}
}
 
?>
<!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 name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">
  <table width="200" border="0" cellspacing="2" bgcolor="#F2F2F2">
    <tr>
      <td>วิชา</td>
      <td><label>
        <select name="select" size="1" id="select">
		<?php
		$result = mysql_query("SELECT * FROM course;");
		while($data = mysql_fetch_array($result)){
		echo "<option>{$data['cou_name']}</option>";
		}
		?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td>ระดับชั้น</td>
      <td><label></label></td>
    </tr>
    <tr>
      <td>ห้องเรียน</td>
      <td><label></label></td>
    </tr>
    <tr>
      <td> </td>
      <td><label>
        <input type="submit" name="Submit" value="เพื่ม">
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>
 
 
  Tag : PHP, MySQL, CakePHP               
                        | 
           
          
            
		
  ประวัติการแก้ไข 2010-12-25 20:27:27	
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2010-12-25 19:44:24 | 
                      By :
                          ja_14436 | 
                      View :
                          1228 | 
                      Reply :
                          10 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |