|
 |
|
สอบถามเกี่ยวกับการส่งค่า และรับค่าจาก checkbox แบบนี้ครับ |
|
 |
|
|
 |
 |
|
ตามรูปนี้ ผมต้องการบันทึกรถแต่ละคัน ว่ามีการใช้งานวันที่เท่าไหร่บ้างในแต่ละเดือน จะส่งค่าไปบันทึกยังไงครับ อยากได้แค่ id รถกับ ว/ด/ป ที่ใช้ 

Code (PHP)
<?php
$y = date("Y");
if (isset($_POST['month'])){
$m=$_POST['month'];
$cy=$_POST['year'];
$viewmonth = "$m-1-$cy";
}else{
$m = date("n");
$y = date("Y");
$viewmonth = date("n-j-Y",strtotime("+0 months"));
}
list($thisMonth,$thisDay,$thisYear) = preg_split('/[\/\-\ \,\.]/', $viewmonth);
$daysinmonth=date("t", mktime(0,0,0,$thisMonth,$thisDay,$thisYear));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calendar Plan</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.table{
background-color:#ddd;
font-family:arial;
font-size:14px;
margin-top: 50px;
}
</style>
<script language=javascript>
function j() {
document.frmPM.pm.value = "on";
alert("Yes!!!");
}
</script>
</head>
<body>
<form name="frmPM" align="center" action="">
<select name="month" onchange="this.form.submit()">
<?php
$months = array(1=>"มกราคม", 2=>"กุมภาพันธ์", 3=>"มีนาคม", 4=>"เมษายน", 5=>"พฤษภาคม", 6=>"มิถุนายน", 7=>"กรกฎาคม", 8=>"สิงหาคม", 9=>"กันยายน", 10=>"ตุลาคม", 11=>"พฤศจิกายน", 12=>"ธันวาคม");
foreach ($months as $month =>$shown_month){
if (isset($_POST['month'])){
$selected_month=($_POST['month']==$month ? 'selected="selected"':'');
}else{
$selected_month=($m==$month ? 'selected="selected"':'');
}
echo "<option value=\"$month\" $selected_month>$shown_month</option>";
}
?>
</select>
<select name="year" onchange="this.form.submit()">
<?php
foreach(range($y,($y+1)) as $year){
if (isset($_POST['year'])){
$selected_year=($_POST['year']==$year ? 'selected="selected"':'');
}else{
$selected_year=($y==$year ? 'selected="selected"':'');
}
echo "<option value=\"$year\" $selected_year>$year</option>";
}
?>
</select>
<?php
$i=1;
$ii=1;
echo"<table class=\"table\" align=\"center\" width=\"90%\">\r";
echo "<colgroup style='background-color:#efefef'></colgroup>\r";
while ($ii<($daysinmonth+1)){
$fd2 = date("D", mktime(0, 0, 0, $thisMonth, $ii, $thisYear));
if ($fd2 == 'Sat' OR $fd2 == 'Sun'){
echo "<colgroup style='background-color:#ff0000'></colgroup>\r";
}
else{
echo "<colgroup style='background-color:#ffffff'></colgroup>\r";
}
$ii=$ii+1;
}
echo "<tr style=\"font-size:.9em;\">\r<th>ทะเบียนรถ</th>\r";
while ($i<($daysinmonth+1)){
$fd = date("D", mktime(0, 0, 0, $thisMonth, $i, $thisYear));
if ($fd == 'Sat' OR $fd == 'Sun'){ //ถ้าเป็นเสาร์ หรืออาทิตย์ให้ hilight สีแดง
echo "<th align=\"center\" width=\"25\" style='background-color:#ff0000'>";
switch($fd){
case Sun:
echo "อา";
break;
case Mon:
echo "จ";
break;
case Tue:
echo "อ";
break;
case Wed:
echo "พ";
break;
case Thu:
echo "พฤ";
break;
case Fri:
echo "ศ";
break;
default:
echo "ส";
break;
}
echo "<br />$i</th>\r"; // วันที่
}
else{
echo "<th align=\"center\" width=\"25\">";
switch($fd){
case Sun:
echo "อา";
break;
case Mon:
echo "จ";
break;
case Tue:
echo "อ";
break;
case Wed:
echo "พ";
break;
case Thu:
echo "พฤ";
break;
case Fri:
echo "ศ";
break;
default:
echo "ส";
break;
}
echo "<br />$i</th>\r";
}
$i=$i+1;
}
echo "</tr>\r";
include 'conn.php';
$rs = mysql_query("select * from tb_car order by car_id asc");
$rows = array();
while($row = mysql_fetch_assoc($rs)){
$car_no = $row['car_no'];
$car_id = $row['car_id'];
echo "<tr>\r<td align=\"left\">$car_no <input type=\"hidden\" name=\"car\" value=\"$car_id\"></td>\r";
for ($d=1; $d<=$daysinmonth; $d++){
//DB query could be here for current date and link added to this cell
echo "<td align=\"center\"><input type=\"checkbox\" id=\"chk\" name=\"chk\"></td>\r";
}
echo "</tr>\r";
}
echo "</table>\r";
echo "<br>";
?>
<tr>
<td align="center">
<input type="submit" name="save" value="บันทึก">
</td>
</tr>
</form>
</body>
</html>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2014-06-14 15:39:59 |
By :
giverplus |
View :
908 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาไปประยุกต์ดูนะครับ
Code (PHP)
<?php
$y = date("Y");
$save = empty($_REQUEST['save']) ? "" : $_REQUEST['save'];
$m = empty($_REQUEST['month']) ? "" : $_REQUEST['month'];
if(!empty($save)){
echo "<pre>"; print_r($_REQUEST); echo "</pre>";
}
if(empty($m)){
$m = date("n");
$y = date("Y");
$viewmonth = date("n-j-Y",strtotime("+0 months"));
} else{
$m=$_REQUEST['month'];
$cy=$_REQUEST['year'];
$viewmonth = "$m-1-$cy";
}
list($thisMonth,$thisDay,$thisYear) = preg_split('/[\/\-\ \,\.]/', $viewmonth);
$daysinmonth=date("t", mktime(0,0,0,$thisMonth,$thisDay,$thisYear));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calendar Plan</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.table{
background-color:#ddd;
font-family:Tahoma;
font-size:14px;
margin-top: 10px;
}
</style>
<script language=javascript>
function j() {
document.frmPM.pm.value = "on";
alert("Yes!!!");
}
</script>
</head>
<body>
<form id="form1" name="frmPM" method="post" action="">
<?php
$i=1;
$ii=1;
echo"<table class=\"table\" align=\"center\" width=\"90%\" border=1>\r";
?>
<tr><td colspan="<?=$daysinmonth+1?>" style='background-color:#ffffff'><select name="month" onchange="this.form.submit()">
<?php
$months = array(1=>"มกราคม", 2=>"กุมภาพันธ์", 3=>"มีนาคม", 4=>"เมษายน", 5=>"พฤษภาคม", 6=>"มิถุนายน", 7=>"กรกฎาคม", 8=>"สิงหาคม", 9=>"กันยายน", 10=>"ตุลาคม", 11=>"พฤศจิกายน", 12=>"ธันวาคม");
foreach ($months as $month =>$shown_month){
if (isset($_POST['month'])){
$selected_month=($_POST['month']==$month ? 'selected="selected"':'');
}else{
$selected_month=($m==$month ? 'selected="selected"':'');
}
echo "<option value=\"$month\" $selected_month>$shown_month</option>";
}
?>
</select>
<select name="year" onchange="this.form.submit()">
<?php
foreach(range($y,($y+10)) as $year){
if (isset($_POST['year'])){
$selected_year=($_POST['year']==$year ? 'selected="selected"':'');
}else{
$selected_year=($y==$year ? 'selected="selected"':'');
}
echo "<option value=\"$year\" $selected_year>$year</option>";
}
?>
</select> <input type="submit" name="save" value="บันทึก"></td></tr>
<?php
echo "<colgroup style='background-color:#efefef'></colgroup>\r";
while ($ii<($daysinmonth+1)){
$fd2 = date("D", mktime(0, 0, 0, $thisMonth, $ii, $thisYear));
if ($fd2 == 'Sat' OR $fd2 == 'Sun'){
echo "<colgroup style='background-color:#ff0000'></colgroup>\r";
}
else{
echo "<colgroup style='background-color:#ffffff'></colgroup>\r";
}
$ii=$ii+1;
}
echo "<tr style=\"font-size:.9em;\">\r<th>ทะเบียนรถ</th>\r";
while ($i<($daysinmonth+1)){
$fd = date("D", mktime(0, 0, 0, $thisMonth, $i, $thisYear));
if ($fd == 'Sat' OR $fd == 'Sun'){ //ถ้าเป็นเสาร์ หรืออาทิตย์ให้ hilight สีแดง
echo "<th align=\"center\" width=\"25\" style='background-color:#ff0000'>";
switch($fd){
case "Sun":
echo "อา";
break;
case "Mon":
echo "จ";
break;
case "Tue":
echo "อ";
break;
case "Wed":
echo "พ";
break;
case "Thu":
echo "พฤ";
break;
case "Fri":
echo "ศ";
break;
default:
echo "ส";
break;
}
echo "<br />$i</th>\r"; // วันที่
}
else{
echo "<th align=\"center\" width=\"25\">";
switch($fd){
case "Sun":
echo "อา";
break;
case "Mon":
echo "จ";
break;
case "Tue":
echo "อ";
break;
case "Wed":
echo "พ";
break;
case "Thu":
echo "พฤ";
break;
case "Fri":
echo "ศ";
break;
default:
echo "ส";
break;
}
echo "<br />$i</th>\r";
}
$i=$i+1;
}
echo "</tr>\r";
#include 'conn.php';
#$rs = mysql_query("select * from tb_car order by car_id asc");
$rows = array();
#while($row = mysql_fetch_assoc($rs)){
for($i=1; $i<=4;$i++ ){
echo "<tr>\r<td align=\"left\">คันที่ $i <input type=\"hidden\" name=\"car\" value=\"$i\"></td>\r";
for ($d=1; $d<=$daysinmonth; $d++){ #วันที่
echo "<td align=\"center\"><input type=\"checkbox\" id=\"chk\" name=\"chk[$i][$d]\"></td>\r";
}
echo "</tr>\r";
}
echo "</table>\r";
echo "<br>";
?>
</form>
</body>
</html>
deawx
[email protected]
ปรึกษา php ฟรีจ้า
|
 |
 |
 |
 |
Date :
2014-06-15 02:33:57 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆ เลยครับ 
|
 |
 |
 |
 |
Date :
2014-06-15 11:05:11 |
By :
giverplus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|