|
 |
|
รบกวนช่วยดูหน่อยครับ ตอนนี้ผมยังทำไม่ถูกเลยครับ ไงรบกวนพวกคุณที่เก่งๆช่วยผมหน่อยน่ะครับ |
|
 |
|
|
 |
 |
|
ตอนนี้ผมยังทำไม่ถูกเลยครับ
ไงรบกวนพวกคุณที่เก่งๆช่วยผมหน่อยน่ะครับ
ส่วนที่ผมจะให้พวกคุณช่วยดู จะเป็นการจัดรถตู้โดยการรันหมายเลข รถตู้ จัดให้คนนั่งโดยมีเงื่อนไขต่างๆดังนี้ครับ
ดูรูปภาพประกอบน่ะครับ

โดยขั้นแรก ผมจะดึงข้อมูลออกมาจาก ฐานข้อมูลโดยการ GROUP แต่ละ สาย ออกมา ซึ่งในที่นี้คือ ROUTE
แล้วค่อยมาเปรียบเทียบแบ่งเป็น GROUPๆๆๆ
โดยที่ข้อมูลที่ดึงออกมา และเกี่ยวข้องคือ
1 ROUTE NAME ไว้เปรียบเทียบ ถ้าไม่ตรงกับ ROUTE NAME เดิมก็ให้ขึ้น GROUP ใหม่
2 point จะเป็นการแสดง จุดๆๆที่รถจอดครับ
3 icount คือ จำนวนคนน่ะจุดนัน้นๆๆครับ
เงื่อนไขคือ
1. นับจำนวนคนในสายนั้น โดยนับตั้งแต่จุดแรก จนจุดสุดท้าย ของสายนั้น นับมาเรื่อยๆ ครบ 10 คนจัดหนึ่งคัน
ก็คือ ใส่ตัวเลข VAN1 เข้าไปครับ แต่ถ้านับมาเรื่อยๆพอมาถึงจุดหนึ่งแล้วเกิน 10 มันจะไม่ตรงหลักความจริงครับ จะต้องข้ามส่วนนั้นไป แล้วนับต่อไป จนครบ 10 และไม่เกินสายนั้นๆครับ ถ้าพอถึงจุดสุดท้ายของสายนั้นแต่ยังไม่ครบ 10 ก็ไม่เป็นไรครับ ดังตัวอย่างรูปแรก ณ Route พนัส point ตั้งแต่ ก่อมีเจริญ จนถึง วัดหนองกะขะ
พอนับแล้วมันจะได้ 11 ครับ ซ่งจะไม่ตรงหลักความจริง ผมต้องข้ามส่วนนี้ไปก่อนแล้วนับจุดต่อไปให้ครบ 10 พอดี
พอครบ 10 แล้วก็ต้องเพิ่มคันใหม่ ก็คือ เพิ่มตัวเลขที่รัน + 1 ถ้านับจำนวนจุดไม่ครบตลอดทั้งสายก็นับใหม่และต้องนับส่วนที่ข้ามด้วยครับ ดังตัวอย่าง
2. ถ้าเป็นคนละสายแล้ว ให้จัดรถตู้คันใหม่ ในที่นี้ ก็เพิ่มตัวเลขที่รัน +1 เข้าไปไม่ว่าสายที่ผ่านมาจะนับจำนวนคนแล้วไม่ถึง 10 ก็จัดรถตู้คันใหม่ครับ
3. แล้วถ้าแต่ละจุดมีจำนวนคน(count)เกินมากกว่า 10 คน อย่างเช่น ในรูปข้างล่าง จุดคอนโดบุญนครจะมีคน 11คน จะต้องแบ่งคน แล้วจัดรถตู้ แล้วนำเศษที่ได้ป่ายนับจำนวนคนน่ะจุดต่อไปครับ

ที่ผมอยากทราบว่าในด้านการเขียน
1.จะมีครายพอแนะนำวิธีได้มั่งครับ
2.ผมได้นำCodeมาให้ดูด้วยครับ ผมยอมรับว่ารีบปั่น และยังมี BUG อยู่มาก ผมอยากจะทราบว่าผมควรทำยังไงดี
3.ควรจัดโค๊ดยังไงดี เพราะใช้ IF FOR พวกนี้เยอะมาก มันจะเป็นปัญหาตอนเค้าเปลี่ยน REquirement
4.ช่วยแนะนำวิธีคิดในการแก้ไขปัญหาทั้งสามหน่อยครับ หรือ เขียน code ตัวอย่างหน่อยก็ดีครับ
ขอบคุณมากน่ะครับ
ขออภัยถ้าไม่เข้าใจในคำถามครับ แต่ไงก็รบกวน ตอบในกะทู้นี้หน่อยน่ะครับ
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=utf-8" />
<title>Route Point Person</title>
<script type="text/javascript" src="../library/jQuery/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// toggles the slickbox on clicking the noted link
//$.unique(document.getElementsByTagName("div"));
//$.unique(document.getElementsByTagName("a"));
// div textbox
$('div.slickbox').hide();
$('a.Confirm').hide();
$('a.Cancle').hide();
$('div.divTxtVanName').hide();
// Edit Click
$('a.edit').click(function() {
//สร้าง id ขึ้นมาเพื่อจะเข้าถึง แต่ละตัว
var idi = $(this).attr('id');
var myStr=new String(idi);
var tmp = $("div.slickbox:eq("+ myStr +")").attr('id');
$('div.slickbox:eq('+idi+')').show();
$('div.divTxtVanName:eq('+idi+')').show();
//alert(idi);
var div1text = $("div.divvlauecout:eq("+ myStr +")").text(),
vanName = $("div.divVanName:eq("+ myStr +")").text();
$('.icount:eq('+ myStr +')').val(div1text);
$('.txtVanName:eq('+ myStr +')').val(vanName);
$("div.divvlauecout:eq("+ myStr +")").hide();
$("div.divVanName:eq("+ myStr +")").hide();
//alert(div1text);
$('a.Confirm:eq('+ myStr +')').show();
$('a.edit:eq('+ myStr +')').hide();
$('a.Cancle:eq('+ myStr +')').show();
//.toggle(400);
return false;
});
//Cancle Click
$('a.Cancle').click(function() {
var idi = $(this).attr('id');
var myStr=new String(idi);
$('div.slickbox:eq('+idi+')').hide();
$("div.divvlauecout:eq("+ myStr +")").show();
$('div.divTxtVanName:eq('+idi+')').hide();
$("div.divVanName:eq("+ myStr +")").show();
$('a.Confirm:eq('+ myStr +')').hide();
$('a.edit:eq('+ myStr +')').show();
$('a.Cancle:eq('+ myStr +')').hide();
});
//Confirm Click
$('a.Confirm').click(function() {
var id_confirm_btn = $(this).attr('id'),
id_confirm_btn_str=new String(id_confirm_btn),
idi_div_total = $(this).parent().parent().parent().parent().parent().parents().siblings().filter("#GrandTotal").children().siblings().eq(1).children().attr('id'),
txt_count_person = $('.icount:eq('+ id_confirm_btn_str +')').val(), //alert(txt_count_person);
div_count_person = $("div.divvlauecout:eq("+ id_confirm_btn_str +")").text(), //alert(div_count_person)
count_total= $("div.divcoutall:eq("+ idi_div_total +")").text(),
vanName = $('.txtVanName:eq('+ id_confirm_btn_str +')').val(),
divCountPerson = $('div.divCountPerson:eq('+ id_confirm_btn_str +')').text(),
//div_van_name = $("div.divVanName:eq("+ id_confirm_btn_str +")").text(),
tmp_value_diff = 0;
//var idi_div_total = $("div.divcoutall:eq("+ id_confirm_btn_str +")").attr('id')
//var idi_div_total = $(this).parents attr('id');
//id ของdiv total เป็นการอ้างถึง element ใน html โดยเริ่มจาก Confirm link ไฟยัง div total ตำแหน่ง total
//var idi_div_total = $("div.divcoutall").attr('id');
//alert(idi_div_total);
if((div_count_person<=txt_count_person) && txt_count_person!=0)
{ //alert(txt_count_person);
tmp_value_diff = parseInt(txt_count_person) - parseInt(div_count_person);
count_total = parseInt(count_total) + parseInt(tmp_value_diff);
}
else
{
tmp_value_diff = parseInt(div_count_person) - parseInt(txt_count_person);
count_total = parseInt(count_total) - parseInt(tmp_value_diff);
//alert(count_total);
}
//alert($(this).siblings().length);
$("div.divVanName:eq("+ id_confirm_btn_str +")").text(vanName);
$("div.divvlauecout:eq("+ id_confirm_btn_str +")").text(txt_count_person);
$("div.divcoutall:eq("+ idi_div_total +")").text(count_total);
$("div.divvlauecout:eq("+ id_confirm_btn_str +")").show();
$('div.slickbox:eq('+id_confirm_btn+')').hide();
$("div.divVanName:eq("+ id_confirm_btn_str +")").show();
$('div.divTxtVanName:eq('+id_confirm_btn+')').hide();
$('a.Confirm:eq('+ id_confirm_btn_str +')').hide();
$('a.edit:eq('+ id_confirm_btn_str +')').show();
$('a.Cancle:eq('+ id_confirm_btn_str +')').hide();
if(divCountPerson!=txt_count_person)
{
$('tr.trStyleChange:eq('+ id_confirm_btn_str +')').addClass('change');
}
else
{
$('tr.trStyleChange:eq('+ id_confirm_btn_str +')').removeClass('change');
}
});
});
</script>
<style type="text/css">
.change {
background-color: #FF6600; /* pale yellow for odd rows */
}
</style>
<?php
require '../function/Template.php';
require '../function/Connect.php';
require '../function/DateTime.php';
require '../function/ddl_value.php';
Template::get_Css_Template();
?>
</head>
<body>
<form name="myform" id="myform" action="master_table_route_detail.php" method="post">
<?
//$slc_all = "SELECT * from testview ";
$slc_all = "SELECT master_route.routename, master_point.Pointname, COUNT(master_employee.Empcode) AS icount ";
$slc_all.= "FROM master_route, master_point, master_employee ";
$slc_all.= "WHERE (master_employee.PointID = master_point.PointID) AND (master_point.PointID = master_employee.PointID) AND ";
$slc_all.= "(master_route.PointID = master_point.PointID) AND (master_point.PointID = master_route.PointID) ";
$slc_all.= "GROUP BY master_route.routename, master_point.Pointname ";
$result_all = mysql_query($slc_all,$db_con)or die("ไม่สามารถค้นหา ข้อมูล Department ได้");
$i=1;// $i คือ ตัวเลขที่ใช้คำนวณ การสร้างสีครับ
$Num_Rows = mysql_num_rows($result_all);
$result_dep =mysql_query($slc_all,$db_con)or die("ไม่สามารถติดต่อฐานข้อมูลได้");
$result_nvan =mysql_query($slc_all,$db_con)or die("ไม่สามารถติดต่อฐานข้อมูลได้");
$tmp_count = 0;
$tmp_count_van = 0;
$cvan_array;
$Nroute_chk_temp = "";
$count_van_all_temp = 0 ;
$count_van_chk_temp = 0;
$random_num_temp = 0;
$nvan_array;
$index_n_van_arr_tmp = 0;
// เก็บค่าตำแหน่ง ของ array ชื่อ Van ที่มีจำนวนเกินจากการบวก 10
$tmp_index_arr_nvan;
// เก็บค่าตำแหน่ง ของ array จำนวนรถ ที่มีจำนวนเกินจากการบวก 10
$tmp_index_arr_count;
//$tmp_num_van;
/*############### วนลูป เพิ่อเก็บค่า Temp รถตู้ ###############*/
while($row_nvan = mysql_fetch_array($result_nvan))
{
$cvan_array[$index_n_van_arr_tmp] = $row_nvan["icount"];
//echo $count_van_all_temp;
//เก็บจำนวนรถตู้ เพิ่อนำค่าไป Check
$count_van_chk_temp = $count_van_chk_temp + $row_nvan["icount"];
//จำนวนรถตู้ทั้งหมดในแต่ละสาย
$count_van_all_temp = $count_van_all_temp + $row_nvan["icount"];
if($row_nvan["routename"]==$Nroute_chk_temp)
{
if($count_van_chk_temp <=10)
{
$nvan_array[$index_n_van_arr_tmp] ="van".$random_num_temp;
if($count_van_chk_temp==10)
{
$random_num_temp =$random_num_temp +1 ;
$count_van_chk_temp = 0;
}
else if(count($tmp_index_arr_nvan)>0)
{
// อันที่ 2 ของการ set ค่า $nvan_array[$index_n_van_arr_tmp]
//เม้นๆๆมันมาได้ไงว่ะ ออก เฉย เด้วดูๆๆ
//$nvan_array[$index_n_van_arr_tmp]="";
}
}
else
{
//อันที่ 1 ของการ set ค่า $nvan_array[$index_n_van_arr_tmp]
$nvan_array[$index_n_van_arr_tmp] = "";
$count_van_chk_temp = $count_van_chk_temp - $row_nvan["icount"];
//เก็บ Index ของ nvan_array ที่เ้ว้นว่างไว้
$tmp_index_arr_nvan[] = $index_n_van_arr_tmp;
$tmp_index_arr_count[] = $row_nvan["icount"];
//$nvan_array[] = "";
//$nvan_array[] = "";
//$random_num_temp =$random_num_temp +1 ;
//$nvan_array[$index_n_van_arr_tmp]="van".$random_num_temp;
//$count_van_chk_temp = 0;
}
//$nvan_array[] = $count_van_all_temp;
//$count_van_all_temp = $count_van_all_temp + $row_nvan["icount"];
}
// ส่วนนี้จะเป็นส่วน สิ้นสุดแต่ละประเภทสาย
else
{
if($Nroute_chk_temp !="" )
{
$count_van_chk_temp=0;
//echo $tmp_index_arr_nvan[0];
//echo $count_van_all_temp;
//echo count($tmp_index_arr_nvan)."<br>";
/*เป้นการ Set ค่า ให้ array ที่เก็บค่าตัวที่เว้นไว้ เท่ากับ Null */
//echo $count_van_all_temp."<br>";
$count_van_all_temp = 0 ;
$count_van_all_temp = $count_van_all_temp + $row_nvan["icount"];
}
if(count($tmp_index_arr_nvan)>0)
{
if(($count_van_chk_temp>10))
{
$count_van_chk_temp = 0;
}
//ส่วนนี้ที่ Comment จะเป็นส่วน จำนวนรถตู้
//$random_num_temp =$random_num_temp +1 ;
for($i=0; $i<count($tmp_index_arr_nvan);$i++)
{//echo "Test";
//เก็บจำนวนรถตู้ เพิ่อนำค่าไป Check
//echo count($tmp_index_arr_count);
//echo $tmp_index_arr_nvan[0]."<br>";
$count_van_chk_temp = $count_van_chk_temp + $tmp_index_arr_count[$i];
if($count_van_chk_temp <=10)
{
$nvan_array[$tmp_index_arr_nvan[$i]]="van".$random_num_temp;
unset($tmp_index_arr_nvan[$i]);
unset($tmp_index_arr_count[$i]);
if($count_van_chk_temp==10)
{
$random_num_temp =$random_num_temp +1 ;
$count_van_chk_temp = 0;
}
else if(count($tmp_index_arr_nvan)>0)
{
// อันที่ 2 ของการ set ค่า $nvan_array[$index_n_van_arr_tmp]
//เม้นๆๆมันมาได้ไงว่ะ ออก เฉย เด้วดูๆๆ
//$nvan_array[$index_n_van_arr_tmp]="";
}
}
else
{
//อันที่ 1 ของการ set ค่า $nvan_array[$index_n_van_arr_tmp]
$nvan_array[$tmp_index_arr_nvan[$i]] = "";
//echo count($tmp_index_arr_nvan);
$count_van_chk_temp = $count_van_chk_temp - $tmp_index_arr_count[$tmp_index_arr_nvan[$i]];
//เก็บ Index ของ nvan_array ที่เ้ว้นว่างไว้
$tmp_index_arr_nvan[] = $tmp_index_arr_nvan[$i];
echo count($tmp_index_arr_nvan)."<br>";
$tmp_index_arr_count[] = $tmp_index_arr_count[$i];
$random_num_temp =$random_num_temp +1 ;
//unset($tmp_index_arr_nvan);
//$nvan_array[$index_n_van_arr_tmp]="van".$random_num_temp;
//$count_van_chk_temp = 0;
}
}
/*foreach($tmp_index_arr_nvan as $val)
{
$nvan_array[$val] = "van28";
//$val = "van";
}*/
////echo count($tmp_index_arr_nvan);
$tmp_index_arr_nvan = null;
}
$random_num_temp =$random_num_temp +1 ;
//echo $count_van_chk_temp."<br>";
$count_van_chk_temp = 0;
$count_van_chk_temp = $count_van_chk_temp + $row_nvan["icount"];
$nvan_array[$index_n_van_arr_tmp]="van".$random_num_temp;
//$nvan_array[] = $count_van_all_temp;
//ถ้าจำนวนมากกว่า 10 ให้ทำการ แยก เป็น สอง record และแบ่งค่าตัวเลข
if($row_nvan["icount"]>10)
{
for($j= $row_nvan["icount"];$j>0;$j=$j-10)
{ //echo $row_dep["icount"];
if($j<10)
{
//$tmp_count_divide = $j;
$count_van_chk_temp= $j;
$index_n_van_arr_tmp = $index_n_van_arr_tmp +1;
$nvan_array[$index_n_van_arr_tmp]="van".$random_num_temp;
}
else
{
//$tmp_count_divide = "10";
echo $random_num_temp;
$nvan_array[$index_n_van_arr_tmp]="van".$random_num_temp;
$random_num_temp =$random_num_temp +1 ;
//$index_n_van_arr_tmp = $index_n_van_arr_tmp +1;
//$count_van_chk_temp = 0;
//$random_num_temp =$random_num_temp +1 ;
}
}
}
}
$Nroute_chk_temp =$row_nvan["routename"];
$index_n_van_arr_tmp = $index_n_van_arr_tmp +1;
//$tmp_num_van = $row_nvan["icount"];
}
/*############### สิ้นสุด การวนลูป เพื่อเก็บค่า temp name van ###############*/
$tmp_nroute = "";
// index สำหรับ อ้างถึง จำนวน รถตู้ ที่จะ Edit
$index_arr = 0;
// id สำหรับ ปุ่ม คลิ๊ก Edit
$index_toggle = 0;
// id สำหรับ div show textbox
$slick_box = 1;
// id สำหรับ div count van
$div_value_count = 1;
$div_total = 0;
$tmp_count_divide = 0 ;
while($row_dep = mysql_fetch_array($result_dep))
{
$bgcolor =($i++ %2)?'#FFFFFF':'#F3F2F4';
$tmp_count_van = $tmp_count_van + $row_dep["icount"];
//$tmp_name_van =$cvan_array[$index_arr];
//ใส่่ค่าให้กับ ตัวแปร
$tmp_count_van = $cvan_array[$index_arr];
//เปรียบเทียบ ว่าค่ามานตรงกันป่ะกับ DB ในฐานข้อมูล
if($row_dep["routename"]==$tmp_nroute)
{
//เป็นส่วนตรวจสอบ ว่าจำนวนคน ณ จุด นั้นๆมีมากว่า 10 ถ้าเกิน จะสร้าง record ใหม่
if($row_dep["icount"]>10)
{ //echo $row_dep["icount"];
for($i= $row_dep["icount"];$i>0;$i=$i-10)
{ //echo $row_dep["icount"];
if($i<10)
{
$tmp_count_divide = $i;
}
else
{
$tmp_count_divide = "10";
}
?>
<tr bgcolor="<? echo $bgcolor; ?>" class="trStyleChange" id="<? echo $div_value_count; ?>" >
<td height="32" id = '<? echo $row_dep["routeid"];?>'></td>
<td height="32" id = '<? echo $row_dep["Pointname"];?>'><? echo $row_dep["Pointname"]; ?></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divCountPerson"><? echo $row_dep["icount"]; ?></div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divvlauecout"><? echo $tmp_count_divide;?></div>
<div id="<? echo $slick_box;?>" class="slickbox">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="icount" />
</div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divVanName"><? echo $nvan_array[$index_arr]; ?></div>
<div id="<? echo $slick_box;?>" class="divTxtVanName">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="txtVanName" />
</div></td>
<td height="32"><table width="65%" border="0" align="center">
<tr>
<td align="center" id = '<? echo $effDate; ?>' ><a id='<? echo $index_toggle;?>'<? //echo $row_dep["routeid"];?> class='edit' title='Edit'> <img src="../images/edit.png" width="17" height="16" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Confirm' title='Confirm'> <img src="../images/apply.ico" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Cancle' title='Cancle'> <img src="../images/cancel.ico" style="cursor:pointer" /></a> </td>
</tr>
</table></td>
</tr>
<? // index arr สำหรับ อ้าง ถึง name van array
$index_arr = $index_arr + 1;
// index อ้าง ปุ่ม คลิ๊กส่วนไหน
$index_toggle = $index_toggle + 1;
//index div ของ textbox จำนวนคน
$slick_box = $slick_box +1;
// index div ของค่่า จำนวนคน
$div_value_count= $div_value_count +1;
}
$index_arr = $index_arr - 1;
// index อ้าง ปุ่ม คลิ๊กส่วนไหน
$index_toggle = $index_toggle - 1;
//index div ของ textbox จำนวนคน
$slick_box = $slick_box -1;
// index div ของค่่า จำนวนคน
$div_value_count= $div_value_count -1;
}
else
{
// ถ้าตรงกับค่าเดิมให้สร้างตารางต่อไป แสดงว่ายังอยู่ในประเภทเดิม
?>
<tr bgcolor="<? echo $bgcolor; ?>" c class="trStyleChange" id="<? echo $div_value_count; ?>" >
<td height="32" id = '<? echo $row_dep["routeid"];?>'></td>
<td height="32" id = '<? echo $row_dep["Pointname"];?>'><? echo $row_dep["Pointname"]; ?></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divCountPerson"><? echo $row_dep["icount"]; ?></div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divvlauecout"><? echo $tmp_count_van;?></div>
<div id="<? echo $slick_box;?>" class="slickbox">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="icount" />
</div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divVanName"><? echo $nvan_array[$index_arr]; ?></div>
<div id="<? echo $slick_box;?>" class="divTxtVanName">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="txtVanName" />
</div></td>
<td height="32"><table width="65%" border="0" align="center">
<tr>
<td align="center" id = '<? echo $effDate; ?>' ><a id='<? echo $index_toggle;?>'<? //echo $row_dep["routeid"];?> class='edit' title='Edit'> <img src="../images/edit.png" width="17" height="16" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Confirm' title='Confirm'> <img src="../images/apply.ico" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Cancle' title='Cancle'> <img src="../images/cancel.ico" style="cursor:pointer" /></a> </td>
</tr>
</table></td>
</tr>
<?
}
}
else
{
if($tmp_nroute !="")
{
//echo $tmp_count
?>
<tr id="GrandTotal" >
<td colspan="2" id="king">GrandTotal</td>
<td><? echo $tmp_count;?></td>
<td id="ka"><div id="<? echo $div_total;?>" class="divcoutall"><? echo $tmp_count;?></div>
<? $div_total =$div_total+1; //echo $tmp_count; ?>
</td>
<td></td>
<td></td>
</tr>
</table>
<?
$tmp_count = 0;
}
// ส่วน ของ หัว ตาราง ตอนเริ่มต้นประเภทใหม่
?>
<table width="98%" border="0" align="center" cellspacing="1" class="table1" id="table1">
<tr>
<td width="20%" height="20" align="center" bgcolor="#a6b4bb" class="boldwhite">Route</td>
<td width="20%" height="20" align="center" bgcolor="#a6b4bb" class="boldwhite">Point</td>
<td width="17%" align="center" bgcolor="#a6b4bb" class="boldwhite">Count(Person)</td>
<td width="15%" align="center" bgcolor="#a6b4bb" class="boldwhite">Count Edit(Person)</td>
<td width="15%" align="center" bgcolor="#a6b4bb" class="boldwhite">Van</td>
<td width="13%" bgcolor="#a6b4bb" align="center"> </td>
</tr>
<?
//เป็นส่วนตรวจสอบ ว่าจำนวนคน ณ จุด นั้นๆมีมากว่า 10 ถ้าเกิน จะสร้าง record ใหม่
$tmp_routename;
if($row_dep["icount"]>10)
{
for($i= $row_dep["icount"];$i>0;$i=$i-10)
{ //echo $row_dep["icount"];
if($i<10)
{
$tmp_count_divide = $i;
$tmp_routename="";
}
else
{
$tmp_count_divide = "10";
$tmp_routename = $row_dep["routename"];
}
?>
<tr bgcolor="<? echo $bgcolor; ?>" class="trStyleChange" id="<? echo $div_value_count; ?>" >
<td height="32" id = '<? echo $row_dep["routeid"];?>'><? echo $tmp_routename; ?></td>
<td height="32" id = '<? echo $row_dep["Pointname"];?>'><? echo $row_dep["Pointname"]; ?></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divCountPerson"><? echo $tmp_count_divide; ?></div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divvlauecout"><? echo $tmp_count_divide;?></div>
<div id="<? echo $slick_box;?>" class="slickbox">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="icount" />
</div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divVanName"><? echo $nvan_array[$index_arr]; ?></div>
<div id="<? echo $slick_box;?>" class="divTxtVanName">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="txtVanName" />
</div></td>
<td height="32"><table width="65%" border="0" align="center">
<tr>
<td align="center" id = '<? echo $effDate; ?>' ><a id='<? echo $index_toggle;?>'<? //echo $row_dep["routeid"];?> class='edit' title='Edit'> <img src="../images/edit.png" width="17" height="16" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Confirm' title='Confirm'> <img src="../images/apply.ico" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Cancle' title='Cancle'> <img src="../images/cancel.ico" style="cursor:pointer" /></a> </td>
</tr>
</table></td>
</tr>
<? // index arr สำหรับ อ้าง ถึง name van array
$index_arr = $index_arr + 1;
// index อ้าง ปุ่ม คลิ๊กส่วนไหน
$index_toggle = $index_toggle + 1;
//index div ของ textbox จำนวนคน
$slick_box = $slick_box +1;
// index div ของค่่า จำนวนคน
$div_value_count= $div_value_count +1;
}
$index_arr = $index_arr - 1;
// index อ้าง ปุ่ม คลิ๊กส่วนไหน
$index_toggle = $index_toggle - 1;
//index div ของ textbox จำนวนคน
$slick_box = $slick_box -1;
// index div ของค่่า จำนวนคน
$div_value_count= $div_value_count -1;
}
else
{
?>
<tr bgcolor="<? echo $bgcolor; ?>" class="trStyleChange" id="<? echo $div_value_count; ?>">
<td height="32" id = '<? echo $row_dep["routeid"];?>'><? echo $row_dep["routename"]; ?></td>
<td height="32" id = '<? echo $row_dep["Pointname"];?>'><? echo $row_dep["Pointname"]; ?></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divCountPerson"><? echo $row_dep["icount"]; ?></div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divvlauecout"><? echo $tmp_count_van;?></div>
<div id="<? echo $slick_box;?>" class="slickbox">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="icount" />
</div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divVanName"><? echo $nvan_array[$index_arr]; ?></div>
<div id="<? echo $slick_box;?>" class="divTxtVanName">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="txtVanName" />
</div></td>
<td height="32"><table width="65%" border="0" align="center">
<tr>
<td align="center" ><a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='edit' title='Edit'> <img src="../images/edit.png" width="17" height="16" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Confirm' title='Confirm'> <img src="../images/apply.ico" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Cancle' title='Cancle'> <img src="../images/cancel.ico" style="cursor:pointer" /></a> </td>
</tr>
</table></td>
</tr>
<? }
}
$tmp_count = $tmp_count+$row_dep["icount"];
$tmp_nroute =$row_dep["routename"];
// index arr สำหรับ อ้าง ถึง name van array
$index_arr = $index_arr + 1;
// index อ้าง ปุ่ม คลิ๊กส่วนไหน
$index_toggle = $index_toggle + 1;
//index div ของ textbox จำนวนคน
$slick_box = $slick_box +1;
// index div ของค่่า จำนวนคน
$div_value_count= $div_value_count +1;
//echo $index_toggle;
?>
<?
}
if($Num_Rows==0)
{
?>
<tr>
<td colspan="4" align="center" class="normal">ไม่มีข้อมูลในรายการนี้</td>
</tr>
<?
}
?>
<tr id="GrandTotal">
<td colspan="2" id="king">GrandTotal</td>
<td><? echo $tmp_count;?></td>
<td><div id="<? echo $div_total;?>" class="divcoutall"><? echo $tmp_count;?></div>
<? //echo $tmp_count;?>
</td>
<td></td>
<td></td>
</tr>
</table>
<input type="submit" value="submit" />
</form>
</body>
</html>
<?
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-11-07 13:14:28 |
By :
kingnaka |
View :
994 |
Reply :
17 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำให้ถามที่ละคำถามสรุปให้เข้าใจง่ายนิดนึงครับ
เห็นทั้งโค๊ดทั้งรูปแล้ว ผมบอกตรงๆ ขี้เกียจอ่าน 
ถามมาแบบนี้โอกาสที่จะได้คำตอบน้อยมากครับขอบอก
|
 |
 |
 |
 |
Date :
2009-11-07 16:05:10 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
๕๕๕๕
ผมยังเรียบเรียงคำถามไม่ค่อยจะถูกครับ
ถามคำถามแรกก่อนเลยหล่ะกันครับ
1 . ใน myslq_fetch_array ผมสามารถที่จะระบุตำแหน่งของ record ได้ป่ะครับ
|
 |
 |
 |
 |
Date :
2009-11-07 17:00:39 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยัง งง อยู่ ครับ จะช่วยดูไห้ครับ
|
 |
 |
 |
 |
Date :
2009-11-07 18:37:05 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากที่ บอกจาก record น่าจะหาจาก บรรทัดที่ค้นหาหรือเปล่าครับ ถ้าใช่ น่าจะระบบุได้นะว่าจะเอา บรรทัดไหน มั้งครับ
|
 |
 |
 |
 |
Date :
2009-11-07 19:45:06 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับสำหรับทุกคำตอบ
ผมอยากระบุได้ว่า record ที่เท่าไรน่ะครับ เช่น record ก่อนหน้านี้ หรือ record ถัดไป ประมาณนี้ครับ
|
 |
 |
 |
 |
Date :
2009-11-07 21:48:28 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้ายังงั้นต้องทราบว่า ปัจจุบันอยู่ record ที่เท่าไร แล้วค่อย - หรือ + เอาครับ เช่น
$rec='record ปัจจุบัน';
$nextrec=$rec+1;
$prerec=$rec-1;
ไม่แน่ใจว่าใช้ที่ต้องการหรือไม่ครับ
|
 |
 |
 |
 |
Date :
2009-11-07 21:58:16 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช่ครับ แต่เราจะระบุมันยังไงเหรอครับ ตอน fetch array น่ะครับ
เพราะ ปกติ ผม จะ ดึงข้อมูลมาแสดงเหมือนกับที่คุณPlaKriM บอก
while($row = mysql_fetch_array($result))
{
echo $row["routname"];
}
สมมติจะระบุตำแหน่ง ของ record ที่ fecth ออกมาได้ป่ะครับเช่น $row["routname"][1] อะไรประมาณนี้ครับ
ปล.ขอบคุณมากจริงๆครับ ต่อไปจะหัดเรียบเรียงคำพูดให้ดีกว่านี้ครับ
|
 |
 |
 |
 |
Date :
2009-11-07 22:38:19 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแบบนี้ดูครับ
Code (PHP)
$sql=" select ........................";
$qurey=......................... // ที่ค้นหาครับ
$row=mysql_num_rows($qurey);
$i=1;
while($i<$row) {
$result=mysql_fetch_array($qurey);
$routname=$result[routname];
echo "$routname record ที่ $i" ;
$i++;
}
ไม่แน่ใจว่าใช่ที่ต้องการหรือไม่นะครับ
|
 |
 |
 |
 |
Date :
2009-11-07 23:07:28 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ครับ
เดี๋ยวลองนำวิธีการนี้ไปดู ครับ ขอบคุณมากครับ
อีกคำถามครับ
Code (PHP)
<tr bgcolor="<? echo $bgcolor; ?>" class="trStyleChange" id="<? echo $div_value_count; ?>" >
<td height="32" id = '<? echo $row_dep["routeid"];?>'></td>
<td height="32" id = '<? echo $row_dep["Pointname"];?>'><? echo $row_dep["Pointname"]; ?></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divCountPerson"><? echo $row_dep["icount"]; ?></div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divvlauecout"><? echo $tmp_count_van;?></div>
<div id="<? echo $slick_box;?>" class="slickbox">
<input type="text" name="icount[]" id="<? echo $div_value_count;?>" class="icount" />
</div></td>
<td height="32" id = '<? echo $row_dep["icount"]; ?>' ><div id="<? echo $div_value_count;?>" class="divVanName"><? echo $nvan_array[$index_arr]; ?></div>
<div id="<? echo $slick_box;?>" class="divTxtVanName">
<input type="text" name="VName[]" id="<? echo $div_value_count;?>" class="txtVanName" />
</div></td>
<td height="32"><table width="65%" border="0" align="center">
<tr>
<td align="center" id = '<? echo $effDate; ?>' ><a id='<? echo $index_toggle;?>'<? //echo $row_dep["routeid"];?> class='edit' title='Edit'> <img src="../images/edit.png" width="17" height="16" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Confirm' title='Confirm'> <img src="../images/apply.ico" style="cursor:pointer" /></a> <a id='<? echo $index_toggle;?>' <? //echo $row_dep["routeid"];?> class='Cancle' title='Cancle'> <img src="../images/cancel.ico" style="cursor:pointer" /></a> </td>
</tr>
</table></td>
</tr>
ผมจำเป้นต้องใช้โค๊ดส่วนนี้หลายจุดน่ะครับ
ผมอยากทราบว่าถ้าแยก โค๊ดส่วนนี้ไปเขียนอีกไฟล์ แล้วก็ใช้ include ในแต่ละจุดที่ต้องการใช้ได้
|
 |
 |
 |
 |
Date :
2009-11-07 23:30:17 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้ยังไม่เคยใช้เหมือนกันครับ ยังตอบไม่ได้ครับ เด๋วลองดูก่อนครับ
|
 |
 |
 |
 |
Date :
2009-11-07 23:40:15 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แยกได้ครับ แต่อย่าสับสนเองละกัน อะไรที่ใช้ร่วมกันหลายๆ ที่แยกออกมาดีกว่า เวลาแก้ไขจะได้แก้ที่เดียว
|
 |
 |
 |
 |
Date :
2009-11-08 00:55:12 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ ทั้งคุณPlaKriM และคุณtong มากๆๆครับ เดี๋ยวถ้าติดอะไรค่อยมาpost หัวข้อใหม่
อิอิ
|
 |
 |
 |
 |
Date :
2009-11-08 01:27:55 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมรบกวนมาถามคำถามอีกครับ
จากรูปแรกข้างล่างจะเป็นตารางฐานข้อมูลที่select มาได้น่ะครับ

ส่วนรูปที่สองเป็นผลลัพธ์ที่จะให้เป็นครับ

ผมอยากทราบว่าแนวทางผมถูกหรือเปล่าน่ะครับ คือ query ข้อมูลออกมา แล้วเปรียบเทียบ ชื่อ กลุ่ม ถ้าต่างกันก็ให้สร้าง ตารางใหม่ขึ้นมาครับ
รบกวนช่วยตอบด้วยครับ
|
 |
 |
 |
 |
Date :
2009-11-12 20:52:11 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อะไรหละนั้น เห็นหมดเลยใครออนเอมบ้าง เหอะๆๆๆๆ ยอรูปนิดนึงนะครับครั้งหน้ามันใหญ่เกินดูไปแล้วงง ครับ อิอิ
|
 |
 |
 |
 |
Date :
2009-11-12 22:23:23 |
By :
nerobenz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ผิดหรอกครับ แล้วแต่จะออกแบบอะ
|
 |
 |
 |
 |
Date :
2009-11-12 22:33:42 |
By :
plakrim |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กลับมาถามอีกครั้งครับ
อิอิ
คราวนี้ผมจะถามคำถามตั้งแต่ส่วนแรกสุดที่อยากได้เลยครับ
ถ้าผม query ข้อมูลออกมา ซึ่งข้อมูลที่ได้มาเป็นจำนวนตัวเลข
ผมจะนำข้อมูลตัวเลขเหล่านั้นมาบวกกันให้ครบ 10 พอดี ถ้าไม่ครบ 10 ก็ให้ข้ามมานับตัวต่อไป
หลังจากหมดชุด query แล้ว ก็จะเหลือตัวที่ถูกว่างไว้ เพราะมัน บวกกกันแล้วเกิน10 นำ ตัวเลขที่เว้นว่างไว้มาบวกกันต่อ จนชุด query เหล่านั้นถูกบวกกันจนครบ
อิอิ
อยากรบกวนเขียน Code ให้ดูหน่อยได้ป่ะครับ
|
 |
 |
 |
 |
Date :
2009-11-16 14:43:53 |
By :
kingnaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|