|
|
|
อยากได้ตารางเรียนค่ะ ตอนนี้แก้ error ไม่ได้ช่วยทีนะค่ะ |
|
|
|
|
|
|
|
Code (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=windows-874" />
<title>:: ตารางเรียน ::</title>
<style type="text/css">
<!--
.style2 {font-size: 12px}
.style3 {color: #FFFFFF}
-->
</style>
<script language="javascript">
function change_bg(obj,id) {
//alert(obj.checked);
//alert(obj.value);
var frm = document.forms[0];
var message = "";
var objID = "";
var chkRow = obj.value;
chkRow = chkRow.substr(0,2);
var chkDiff = 0;
var loop = 0;
var chkOver = 0;
for (i = 0; i < frm.elements['use_time[]'].length; i++) {
objID = frm.elements['use_time[]'][i].id;
if (frm.elements['use_time[]'][i].checked){
message = frm.elements['use_time[]'][i].value;
loop++;
}
message = message.substr(0,2);
if (message == chkRow) {
if (loop > 5) {
chkOver = 1;
} //end if
} else {
if (loop > 0) {
chkDiff = 1;
} //end if
} //end if
} //end for
if (chkDiff == 1) {
alert('กรุณาเลือกในวันเดียวกัน หรือแถวเดียวกันเท่านั้น');
obj.checked = false;
} //endif
if (chkOver == 1) {
alert('กรุณาเลือกจำนวนชั่วโมงไม่เกิน 5 ชั่วโมงติดต่อกัน');
obj.checked = false;
} //endif
var color;
if (obj.checked) {
//color = "#0099FF";
color = "#FF9900"; //สีส้ม
} else {
color = "#009900"; // สีเขียว
} //end if
if (document.getElementById)
{
var thestyle= eval ('document.getElementById("'+id+'").style');
thestyle.backgroundColor=color;
}
} //end function
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
</head>
<body>
<!--ใส่วันที่ได้ที่่ตรงนี้ -->
<?php
$L_w[1]="จันทร์";
$L_w[]="อังคาร";
$L_w[]="พุธ";
$L_w[]="พฤหัส";
$L_w[]="ศุกร์";
$L_w[]="เสาร์";
$L_w[]="อาทิตย์";
?>
<?php
if(!isset($_POST[Submit])){
?>
<?php
$connect=mysql_connect("localhost","root","51310084")or die("no connect database");
mysql_query("use test");
mysql_query("SET CHARACTER SET tis620");
$sql="select * from set_table where term_ids='".$_GET[term_ids]."' ";
$result=mysql_query($sql);
$show_data=mysql_fetch_array($result);
$time_max=$show_data[st_time_last]-1;
//echo $show_data[st_id];
?>
</span>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post" name="time_table_set" class="style2">
<table width="75%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td bgcolor="#ffffff">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<?php
for($i=0;$i<=7;$i++){
if($i==0){
$color="#CC6666";
}elseif($i==1){
//$color="#FF9966";
$color="#FFFF99";
//$msg[0]="วันที่ / เวลา";
}elseif($i==2){
$color="#FF99CC";
}elseif($i==3){
$color="#339900";
}elseif($i==4){
$color="#FF9966";
}elseif($i==5){
$color="#66CCFF";
}elseif($i==6){
$color="#CC99FF";
}elseif($i==7){
$color="#FF3399";
}
?>
<tr>
<td align="left" bgcolor="<?php echo $color?>">
<!-- <?php echo $msg[$i]?> -->
<!--<?php echo $date_t[$i]?> -->
<?php
if($i==0){
echo"วันที่ / เวลา";
}else{
echo $L_w[$i];
}
?>
</td>
<?php
for($t=7;$t<=21;$t++){
$connect=mysql_connect("localhost","root","51310084")or die("no connect database");
mysql_query("use test");
mysql_query("SET CHARACTER SET tis620");
$sql2="select * from time_table where tb_time='".$t."' and tb_week='".$i."'";
$result2=mysql_query($sql2);
$num=mysql_num_rows($result2);
$show_data2=mysql_fetch_array($result2);
if($i==0){
$bg="#66CCFF";
}elseif($num==1){
$bg="#0099FF";//สีน้ำเงิน#CC9999
//$bg="#CC99CC";//สีม่วง
//$bg="#CC9999";//สีม่วง2
$borc="red";
}elseif($num==0){
$bg="#009900";
}
?>
<?php
if($num==1 and $show_data2[tb_setting]==1){
?>
<td align="center" bgcolor="<?php echo $bg?>" colspan="<?php echo $show_data2[tb_col]?>" bordercolor="<?php echo $borc?>">
<?php
if($i==0){
$time_next=$t+1;
$time_list=$t.".00"."-".$time_next.".00";
echo $time_list;
}else{
?>
<?php echo $show_data2[tb_subject]?>
<?php
}
?>
</td>
<?php
}elseif($num==0){
?>
<label for="<?php echo $t.$i?>">
<td align="center" id="<?php echo $i.".".$t?>" bgcolor="<?php echo $bg?>">
<?php
if($i==0){
$time_next=$t+1;
$time_list=$t.".00"."-".$time_next.".00";
echo $time_list;
}else{
?>
<input type="checkbox" id="<?php echo $t.$i?>" name="use_time[]" value="<?php echo $i."##".$t."###".$C_DG?>" onclick="change_bg(this,'<?php echo $i.".".$t?>')">
<?php
}
?>
</td>
</label>
<?php
}
?>
<?php
}
?>
</tr>
<?php
}
?>
</table> </td>
</tr>
<tr>
<td align="center">
<input name="Submit" type="submit" value=" ตกลง "/>
</td>
</tr>
</table>
</form>
<?php
}//end if
?>
<?php
if(isset($_POST[Submit])){
if(count($_POST[use_time])==0){
echo"<script>alert('กรุณาเลือกก่อน');history.back();</script>";
}
?>
<form action="insert_time.php" method="post" name="subject">
<input name="cols_table" type="hidden" value="<?php echo count($_POST[use_time])?>" />
<?php
for($i=0;$i<count($_POST[use_time]);$i++){
//echo $_POST[use_time][$i];
?>
<input name="use_time[]" type="hidden" value="<?php echo $_POST[use_time][$i]?>" />
<?php
}
?>
<table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#666666">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td colspan="2" align="center"><span class="style3">รายวิชาที่สอน</span></td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">รายวิชา : </td>
<td align="left" bgcolor="#FFFFFF"><label>
<textarea name="subject" id="subject" cols="35" rows="5"></textarea>
</label></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#FFFFFF"><label>
<input name="set_term" type="hidden" value="<?php echo $_POST[set_term]?>" />
<input type="submit" name="OK_insert" id="OK_insert" value=" ตกลง " />
<input type="button" name="cancel" id="cancel" value=" ยกเลิก " onclick="javascript:navigate('<?php echo $_SERVER['PHP_SELF']?>');"/>
</label></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
..................................................................................................................................................................................................
<!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=windows-874" />
<title>:: บันทึกตารางเรียนตารางสอน ::</title>
</head>
<body>
<?php
$count_max=count($_POST[use_time])-1;
for($i=0;$i<count($_POST[use_time]);$i++){
//echo $_POST[use_time][$i];
$ex=split("##",$_POST[use_time][$i]);
$ex1=split("##",$_POST[use_time][0]);
$ex2=split("##",$_POST[use_time][$count_max]);
$ex_time_max=$ex2[1]+1;
//echo $ex[1];
$connect=mysql_connect("localhost","root","51310084")or die("no connect database");
mysql_query("use test");
mysql_query("SET CHARACTER SET tis620");
$sql="INSERT INTO 'time_table' ('tb_id', 'tb_subject', 'tb_time', 'tb_time_min', 'tb_time_max', 'tb_col', 'tb_week', 'tb_date', 'tb_setting', 'term_ids') VALUES (NULL, '".$_POST[subject]."', '".$ex[1]."', '".$ex1[1]."', '".$ex_time_max."', '".$_POST[cols_table]."', '".$ex[0]."', '', '0', '".$_POST[set_term]."');";
$result=mysql_query($sql)or die("no $sql");
}
$sql3="select max(tb_id)maximum from time_table";
$result3=mysql_query($sql3);
$show_data3=mysql_fetch_array($result3);
$update_t=$show_data3[maximum]-$count_max;
$sql2="UPDATE `time_table` SET `tb_setting` = '1' WHERE `time_table`.`tb_id` ='".$update_t."'";
$result2=mysql_query($sql2)or die("no $sql2");
mysql_close();
?>
<center>บันทึกข้อมูลเรียบร้อยแล้ว</center>
<!--<meta http-equiv="refresh" content="1;url=index.php"> -->
<?php
echo "<script>window.location='index.php'</script>";
?>
<?php
?>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-02-16 13:16:57 |
By :
rungjanjira |
View :
905 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
error ว่าอะไรครับ
|
|
|
|
|
Date :
2012-02-16 13:22:27 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คือโปรแกรมโชว์หน้าตามาแล้วก้อ error
Code
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\www\schdule\index.php on line 99
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\www\schdule\index.php on line 152
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\www\schdule\index.php on line 153
พอเราติกแล้ว save โปรแกรมจาให้พิมพ์ชื่อรายวิชา เมื่อพิมพ์รายวิชาแล้ว save ก็จะ error
Code
no INSERT INTO 'time_table' ('tb_id', 'tb_subject', 'tb_time', 'tb_time_min', 'tb_time_max', 'tb_col', 'tb_week', 'tb_date', 'tb_setting', 'term_ids') VALUES (NULL, 'aa', '12', '12', '14', '2', '1', '', '0', '');
อันนี้คือฐานข้อมูลนะค่ะ
Code
CREATE TABLE `time_table` (
`tb_id` int(10) unsigned zerofill NOT NULL auto_increment,
`tb_subject` varchar(255) NOT NULL,
`tb_time` varchar(2) NOT NULL,
`tb_time_min` varchar(2) NOT NULL,
`tb_time_max` varchar(2) NOT NULL,
`tb_col` varchar(2) NOT NULL,
`tb_week` varchar(1) NOT NULL,
`tb_date` date NOT NULL,
`tb_setting` varchar(1) NOT NULL,
`term_ids` int(10) unsigned zerofill NOT NULL,
PRIMARY KEY (`tb_id`),
KEY `term_ids` (`term_ids`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=90 ;
|
|
|
|
|
Date :
2012-02-16 13:42:53 |
By :
rungjanjira |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|