Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > Code php query ข้อมูลนานมากเลย ประมาน 10-15 วิ /1000 record ช่วยหาทางแก้ทีครับ



 

Code php query ข้อมูลนานมากเลย ประมาน 10-15 วิ /1000 record ช่วยหาทางแก้ทีครับ

 



Topic : 118607



โพสกระทู้ ( 95 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<? 
  session_start();
include"Connect.php";
//if($_SESSION["u_id"] == NULL)
//echo "<meta http-equiv='Refresh' content='0; URL=../index.php'>";
$user_id=$_SESSION["u_id"] ;

$today = date("Y")+543;
$ms = trim(date("Y-m-d")); 
//echo $ms = trim(date("m-d")); 
$mm=date("m");  

$jobsearch=$_GET["jobsearch"];
  $sql = "select * from user  where user_id ='$user_id' "; //เช็คค่าข้อมูลที่ส่งมาจากฟอร์ม
  $dbquery = mysql_db_query($dbname, $sql);
if($row = mysql_fetch_array($dbquery)){
   $user_type=$row[user_type ];
  }
?>


<script language="javascript">

function chack(){




		if(form1.co_number.value==""){
					if(form1.invoice_number.value==""){
			alert("Fill Invoice No OR Co No !!")
			return false;
		}
}

	
	if(form1.billing_status.value==""){
				alert("Fill Billing Status !!")
			return false;
}
	if(form1.billing_status.value=='Billing'){
		if(form1.date.value==""){
			alert("Fill Billing Date !!")
			return false;
		}
}
	if(form1.billing_status.value=='Complete'){
		if(form1.complete_date.value==""){
			alert("Fill Complete Date !!")
			return false;
		}
}	

	if(form1.invoice_number.value!=""){
			if(form1.invoice_date.value==""){
			alert("Fill Invoice Date !!")
			return false;
		}
}
	
	
var allCheckBox = $("[id^='jobcheck']")
var count_checked = allCheckBox.filter(":checked").length; 
if (count_checked == 0)  {
    alert("Please Check At Least One Of The Checkboxes");
	return false;
} 
//else if(count_checked != allCheckBox.length) {
//    alert("some of the check boxs are not checked");
//} 	
	

	 if (confirm('ต้องการที่จะยืนยันข้อมูล')==true)
		{
		
			
		}
else
		{
			alert('You selected to cancel.');
			return false;
		}
		
	
		
}
</script>


<!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>
<link rel="shortcut icon" type="image/x-icon" href="images/JOBV02-01.png" /> 
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/check.js"></script>

<title>JobOrder</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="css/web.css"/>
<style type="text/css">
<!--
tr.tover:hover{
	cursor:pointer;
	background-color:#33FF33;
}

-->
</style>
</head>

<body onLoad="MM_preloadImages('images/home(1).png','images/job(1).png','images/billstatus(1).png','images/payment(1).png','images/logout(1).png','images/star(1).png','images/report(1).png')">

<table width="1280" border="0" align="center" cellpadding="0" cellspacing="0">

    
  <tr>
    <td height="77" colspan="5" align="center"  >
    <p><img src="images/LOGO.png" width="1280" height="250"  /></p>
    </td>
  </tr>
  <tr valign="top">
    <td height="49">
    <? include "menu.php"; ?> 
</td>
  <tr valign="top">
        <td width="627"><form action="#" method="post" name="form" id="form">
      
         <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        
        <tr>
          
          <td width="125">&nbsp;</td>
          <td class="menu">&nbsp;</td>
          <td width="1010">&nbsp;</td>
          </tr>
        <tr>
          <td width="125">&nbsp;</td>
          <td class="menu">Job Order No.</td>
          <td></td>
          </tr>
        <tr>
          <td width="125">&nbsp;</td>
          <td width="145" class="menu"><label for="jobsearch"></label><input type="text" name="jobsearch" id="jobsearch" value="<?=$_GET["jobsearch"];?>" /></td>
          <td><input type="image" name="button" id="button" value="Submit" src="images/SEARCH_31X31_v02.png" formaction="<?=$_SERVER['SCRIPT_NAME'];?>" formmethod="get" /></td>
          </tr>
         </table>
           </form><br /><br />
           <form action="savepayment.php" method="post" name="form1" id="form1"  onsubmit="return chack()" >
         <table width="100%" border="0" align="center" cellpadding="1" cellspacing="0">
           <tr class="thai">
             <td >&nbsp;</td>
             <td  >&nbsp;</td>
             <td width="152"  >&nbsp;</td>
             <td width="698" >วางบิลลูกค้า</td>
           </tr>
           <tr class="table" >
             <td scope="col">&nbsp;</td>
             <td scope="col">&nbsp;</td>
             <td colspan="2" scope="col">&nbsp;</td>
           </tr>
           <tr bgcolor="#414042" class="menu_white" >
             <td width="32" align="left"  scope="col">&nbsp;</td>
             <td width="390" align="left"  scope="col">Job No.</td>
             <td colspan="2" align="left"   scope="col">Job Check.</td>
            
           </tr>
           <tr class="table" >
             <td scope="col">&nbsp;</td>
             <td scope="col">&nbsp;</td>
             <td colspan="2" scope="col">&nbsp;</td>
           </tr>
           <?
          if($jobsearch != ""){

		
		$sql="SELECT * FROM job WHERE job_no like '%$jobsearch%' order by job_no desc ";
		$query=mysql_query($sql);

	while($data=mysql_fetch_array($query)){
	 $i++;
 
				if($i%2==0)
				{
				$bg = "#DDDDDD";
				}
				else
				{
				$bg = "#b4b4b4";
				}

	$sql1="SELECT job_no FROM stock WHERE job_no = '".$data['job_no']."' ";
	$query1=mysql_query($sql1);
	
	if(mysql_num_rows($query1)>=1){
		
			$sql2="SELECT * FROM payment ";
			$sql2.="WHERE job_no = '%".$data['job_no']."%' ";
			$query2=mysql_query($sql2);
			
			if(mysql_num_rows($query2)==0){
				
				/*$sql3="SELECT st_name FROM stock ";
				$sql3.="WHERE st_name NOT IN (
							SELECT SUBSTRING_INDEX(`job_no`,'_',-1) 
							AS part2 FROM payment 
							WHERE `job_no` LIKE '%".$data['job_no']."%'   
							AND SUBSTRING_INDEX(`job_no`,'_',1) != SUBSTRING_INDEX(`job_no`,'_',-1) 
						)
						AND `job_no` LIKE '%".$data['job_no']."%' ";*/
						
				$sql3="SELECT st_name FROM stock ";
				$sql3.="WHERE st_name NOT IN (
							SELECT job_item FROM payment 
							WHERE job_no LIKE '%".$data['job_no']."%'
						)
						AND job_no LIKE '%".$data['job_no']."%' ";
						
				$query3=mysql_query($sql3);		
				
				if(mysql_num_rows($query3)>=1){?>
					<tr bgcolor="<?=$bg;?>" class="tover" >
					 <td align="left" class="item_black"  scope="col">&nbsp;</td>
					 <td align="left"  class="item_black"  scope="col">&nbsp;&nbsp;<? echo $data['job_no'];?>
					  
					   
						 <input type="hidden"  name="user"  value="<? echo $user_id ; ?>">
					 </td>
					 <td colspan="2" align="left"  scope="col">
					 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="jobcheck[]" type="checkbox" id="jobcheck<?=$data['job_no']?>"   value="<? echo $data['job_no'] ; ?>" /></td>
				  
				   </tr>
				<? }
			}
	}else{
			$sql2="SELECT * FROM payment ";
			$sql2.="WHERE job_no = '".$data['job_no']."' ";
			$query2=mysql_query($sql2);
			
			if(mysql_num_rows($query2)==0){?>
				<tr bgcolor="<?=$bg;?>" class="tover">
					 <td align="left" class="item_black"  scope="col">&nbsp;</td>
					 <td align="left"  class="item_black"  scope="col">&nbsp;&nbsp;<? echo $data['job_no'];?>
					  
					   
						 <input type="hidden"  name="user"  value="<? echo $user_id ; ?>">
					 </td>
					 <td colspan="2" align="left"  scope="col">
					 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="jobcheck[]" type="checkbox" id="jobcheck<?=$data['job_no']?>"   value="<? echo $data['job_no']; ?>" /></td>
				  
				   </tr>
			<? }
	}
}?>


           <tr >
             <td align="left"  scope="col">&nbsp;</td>
             <td align="left"   scope="col">&nbsp;</td>
             <td colspan="2" align="left"  scope="col">&nbsp;</td>
         
           </tr>

         </table>
         <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
		    <tr bgcolor="#F0f0f0" >
		      <td width="3%" class="item_black">&nbsp;</td>
             <td width="31%" class="item_black">&nbsp;&nbsp;Item Name</td>
             <td width="66%"><!--<input name="item_name" type="text" id="item_name" size="15" />-->
				&nbsp;<select name="item_name"  id="item_name" style="width:185px;height:20px;" >
				</select>
			 </td>
           </tr>
           <tr bgcolor="#F0f0f0" >
             <td width="3%" class="item_black">&nbsp;</td>
             <td width="31%" class="item_black">&nbsp;&nbsp;CO. No</td>
             <td width="66%">&nbsp;<input name="co_number" type="text" id="co_number" size="15" /></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;PO. No</td>
             <td>&nbsp;<input name="po_number" type="text" id="po_number" size="15" /></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;PO.Upload</td>
             <td>&nbsp;<input type="button" value="Upload" id="btntest"/></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;Billing Amount</td>
             <td>&nbsp;<input name="billing_amount" type="text" id="billing_amount"  size="15"  onkeypress="check_number()" /></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;Billing Date</td>
             <td>   <table width="30%" align="left" bordercolor="<? $bg ;?>">
                            <tr>
                <td align="left"><input name="date" id="date" style="cursor: text" onClick="ds_sh(this);" value="" size="15" readonly />
                </td>
              </tr>
               </table>
               <table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
  <tr><td id="ds_calclass">
</td></tr>
</table></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;Billing Status</td>
             <td>&nbsp;<select name="billing_status" id="billing_status"  style="width:122px" >
                 <option value="">เลือก</option>
                 <option value="Billing">Billing</option>
                 <option value="Complete">Complete</option>
          
             </select></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;INVOICE. No</td>
             <td>&nbsp;<input name="invoice_number" type="text" id="invoice_number" size="15" /></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;INVOICE. Date</td>
             <td><table width="30%" align="left">
                            <tr>
                <td align="left"><input name="invoice_date" id="invoice_date" style="cursor: text" onClick="ds_sh(this);" value="" size="15" readonly />
                </td>
              </tr>
               </table></td>
           </tr>
           <tr bgcolor="#F0f0f0">
             <td class="item_black">&nbsp;</td>
             <td class="item_black">&nbsp;&nbsp;Complete Date</td>
             <td>   <table width="30%" align="left">
                            <tr>
                <td align="left"><input name="complete_date" id="complete_date" style="cursor: text" onClick="ds_sh(this);" value="" size="15" readonly />
                </td>
              </tr>
               </table>
               <table class="ds_box" cellpadding="0" cellspacing="0" id="ds_conclass" style="display: none;">
  <tr><td id="ds_calclass">
</td></tr>
</table></td>
           </tr>
           <tr>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
             <td>&nbsp;</td>
           </tr>
           <tr>
             <td colspan="3" align="center"><input type="image" name="button2" id="button2" value="Submit" src="images/Submit_botton.png" /></td>
           </tr><? } ?>
           </table>
        
        <div></div>
           	<script type="text/javascript">
// <!-- <![CDATA[

// Project: Dynamic Date Selector (DtTvB) - 2006-03-16
// Script featured on JavaScript Kit- http://www.javascriptkit.com
// Code begin...
// Set the initial date.
var ds_i_date = new Date();
ds_c_month = ds_i_date.getMonth() + 1;
ds_c_year = ds_i_date.getFullYear();

// Get Element By Id
function ds_getel(id) {
	return document.getElementById(id);
}

// Get the left and the top of the element.
function ds_getleft(el) {
	var tmp = el.offsetLeft;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetLeft;
		el = el.offsetParent;
	}
	return tmp;
}
function ds_gettop(el) {
	var tmp = el.offsetTop;
	el = el.offsetParent
	while(el) {
		tmp += el.offsetTop;
		el = el.offsetParent;
	}
	return tmp;
}

// Output Element
var ds_oe = ds_getel('ds_calclass');
// Container
var ds_ce = ds_getel('ds_conclass');

// Output Buffering
var ds_ob = ''; 
function ds_ob_clean() {
	ds_ob = '';
}
function ds_ob_flush() {
	ds_oe.innerHTML = ds_ob;
	ds_ob_clean();
}
function ds_echo(t) {
	ds_ob += t;
}

var ds_element; // Text Element...

var ds_monthnames = [
'มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม','มิถุนายน', 'กรกฏาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน' ,'ธันวาคม',
]; // You can translate it for your language.

var ds_daynames = [
'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
]; // You can translate it for your language.

// Calendar template
function ds_template_main_above(t) {
	return '<table cellpadding="3" cellspacing="1" class="ds_tbl">'
	     + '<tr>'
		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_py();">&lt;&lt;</td>'
		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_pm();">&lt;</td>'
		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_hi();" colspan="3">[Close]</td>'
		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_nm();">&gt;</td>'
		 + '<td class="ds_head" style="cursor: pointer" onclick="ds_ny();">&gt;&gt;</td>'
		 + '</tr>'
	     + '<tr>'
		 + '<td colspan="7" class="ds_head">' + t + '</td>'
		 + '</tr>'
		 + '<tr>';
}

function ds_template_day_row(t) {
	return '<td class="ds_subhead">' + t + '</td>';
	// Define width in CSS, XHTML 1.0 Strict doesn't have width property for it.
}

function ds_template_new_week() {
	return '</tr><tr>';
}

function ds_template_blank_cell(colspan) {
	return '<td colspan="' + colspan + '"></td>'
}


function ds_template_day(d, m, y) {
	return '<td class="ds_cell" onclick="ds_onclick(' + d + ',' + m + ',' + y + ')">' + d + '</td>';
	// Define width the day row.
}

function ds_template_main_below() {
	return '</tr>'
	     + '</table>';
}

// This one draws calendar...
function ds_draw_calendar(m, y) {
	// First clean the output buffer.
	ds_ob_clean();
	// Here we go, do the header
	ds_echo (ds_template_main_above(ds_monthnames[m - 1] + ' ' + y));
	for (i = 0; i < 7; i ++) {
		ds_echo (ds_template_day_row(ds_daynames[i]));
	}
	// Make a date object.
	var ds_dc_date = new Date();
	ds_dc_date.setMonth(m - 1);
	ds_dc_date.setFullYear(y);
	ds_dc_date.setDate(1);
	if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
		days = 31;
	} else if (m == 4 || m == 6 || m == 9 || m == 11) {
		days = 30;
	} else {
		days = (y % 4 == 0) ? 29 : 28;
	}
	var first_day = ds_dc_date.getDay();
	var first_loop = 1;
	// Start the first week
	ds_echo (ds_template_new_week());
	// If sunday is not the first day of the month, make a blank cell...
	if (first_day != 0) {
		ds_echo (ds_template_blank_cell(first_day));
	}
	var j = first_day;
	for (i = 0; i < days; i ++) {
		// Today is sunday, make a new week.
		// If this sunday is the first day of the month,
		// we've made a new row for you already.
		if (j == 0 && !first_loop) {
			// New week!!
			ds_echo (ds_template_new_week());
		}
		// Make a row of that day!
		ds_echo (ds_template_day(i + 1, m, y));
		// This is not first loop anymore...
		first_loop = 0;
		// What is the next day?
		j ++;
		j %= 7;
	}
	// Do the footer
	ds_echo (ds_template_main_below());
	// And let's display..
	ds_ob_flush();
	// Scroll it into view.
	ds_ce.scrollIntoView();
}

// A function to show the calendar.
// When user click on the date, it will set the content of t.
function ds_sh(t) {
	// Set the element to set...
	ds_element = t;
	// Make a new date, and set the current month and year.
	var ds_sh_date = new Date();
	ds_c_month = ds_sh_date.getMonth() + 1;
	ds_c_year = ds_sh_date.getFullYear();
	// Draw the calendar
	ds_draw_calendar(ds_c_month, ds_c_year);
	// To change the position properly, we must show it first.
	ds_ce.style.display = '';
	// Move the calendar container!
	the_left = ds_getleft(t);
	the_top = ds_gettop(t) + t.offsetHeight;
	ds_ce.style.left = the_left + 'px';
	ds_ce.style.top = the_top + 'px';
	// Scroll it into view.
	ds_ce.scrollIntoView();
}

// Hide the calendar.
function ds_hi() {
	ds_ce.style.display = 'none';
}

// Moves to the next month...
function ds_nm() {
	// Increase the current month.
	ds_c_month ++;
	// We have passed December, let's go to the next year.
	// Increase the current year, and set the current month to January.
	if (ds_c_month > 12) {
		ds_c_month = 1; 
		ds_c_year++;
	}
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}

// Moves to the previous month...
function ds_pm() {
	ds_c_month = ds_c_month - 1; // Can't use dash-dash here, it will make the page invalid.
	// We have passed January, let's go back to the previous year.
	// Decrease the current year, and set the current month to December.
	if (ds_c_month < 1) {
		ds_c_month = 12; 
		ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid.
	}
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}

// Moves to the next year...
function ds_ny() {
	// Increase the current year.
	ds_c_year++;
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}

// Moves to the previous year...
function ds_py() {
	// Decrease the current year.
	ds_c_year = ds_c_year - 1; // Can't use dash-dash here, it will make the page invalid.
	// Redraw the calendar.
	ds_draw_calendar(ds_c_month, ds_c_year);
}

// Format the date to output.
function ds_format_date(d, m, y) {
	// 2 digits month.
	m2 = '00' + m;
	m2 = m2.substr(m2.length - 2);
	// 2 digits day.
	d2 = '00' + d;
	d2 = d2.substr(d2.length - 2);
	// YYYY-MM-DD
	return y + '-' + m2 + '-' + d2;
}

// When the user clicks the day.
function ds_onclick(d, m, y) {
	// Hide the calendar.
	ds_hi();
	// Set the value of it, if we can.
	if (typeof(ds_element.value) != 'undefined') {
		ds_element.value = ds_format_date(d, m, y);
	// Maybe we want to set the HTML in it.
	} else if (typeof(ds_element.innerHTML) != 'undefined') {
		ds_element.innerHTML = ds_format_date(d, m, y);
	// I don't know how should we display it, just alert it to user.
	} else {
		alert (ds_format_date(d, m, y));
	}
}

// And here is the end.

// ]]> -->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title></title>

<script type="text/JavaScript">
<!--

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_timelineStop(tmLnName) { //v1.2
  //Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Macromedia, Inc. All rights reserved.

  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  if (tmLnName == null)  //stop all
    for (var i=0; i<document.MM_Time.length; i++) document.MM_Time[i].ID = null;
  else document.MM_Time[tmLnName].ID = null; //stop one
}

function MM_timelineGoto(tmLnName, fNew, numGotos) { //v2.0
  //Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Macromedia, Inc. All rights reserved.
  var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,lastKeyFr,propNum,theObj;
  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  tmLn = document.MM_Time[tmLnName];
  if (numGotos != null)
    if (tmLn.gotoCount == null) tmLn.gotoCount = 1;
    else if (tmLn.gotoCount++ >= numGotos) {tmLn.gotoCount=0; return}
  jmpFwd = (fNew > tmLn.curFrame);
  for (i = 0; i < tmLn.length; i++) {
    sprite = (jmpFwd)? tmLn[i] : tmLn[(tmLn.length-1)-i]; //count bkwds if jumping back
    if (sprite.charAt(0) == "s") {
      numKeyFr = sprite.keyFrames.length;
      firstKeyFr = sprite.keyFrames[0];
      lastKeyFr = sprite.keyFrames[numKeyFr - 1];
      if ((jmpFwd && fNew<firstKeyFr) || (!jmpFwd && lastKeyFr<fNew)) continue; //skip if untouchd
      for (keyFrm=1; keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]; keyFrm++);
      for (j=0; j<sprite.values.length; j++) {
        props = sprite.values[j];
        if (numKeyFr == props.length) propNum = keyFrm-1 //keyframes only
        else propNum = Math.min(Math.max(0,fNew-firstKeyFr),props.length-1); //or keep in legal range
        if (sprite.obj != null) {
          if (props.prop2 == null) sprite.obj[props.prop] = props[propNum];
          else        sprite.obj[props.prop2][props.prop] = props[propNum];
      } }
    } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
  }
  tmLn.curFrame = fNew;
  if (tmLn.ID == 0) eval('MM_timelinePlay(tmLnName)');
}

function MM_timelinePlay(tmLnName, myID) { //v1.2
  //Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Macromedia, Inc. All rights reserved.
  var i,j,tmLn,props,keyFrm,sprite,numKeyFr,firstKeyFr,propNum,theObj,firstTime=false;
  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  tmLn = document.MM_Time[tmLnName];
  if (myID == null) { myID = ++tmLn.ID; firstTime=true;}//if new call, incr ID
  if (myID == tmLn.ID) { //if Im newest
    setTimeout('MM_timelinePlay("'+tmLnName+'",'+myID+')',tmLn.delay);
    fNew = ++tmLn.curFrame;
    for (i=0; i<tmLn.length; i++) {
      sprite = tmLn[i];
      if (sprite.charAt(0) == 's') {
        if (sprite.obj) {
          numKeyFr = sprite.keyFrames.length; firstKeyFr = sprite.keyFrames[0];
          if (fNew >= firstKeyFr && fNew <= sprite.keyFrames[numKeyFr-1]) {//in range
            keyFrm=1;
            for (j=0; j<sprite.values.length; j++) {
              props = sprite.values[j]; 
              if (numKeyFr != props.length) {
                if (props.prop2 == null) sprite.obj[props.prop] = props[fNew-firstKeyFr];
                else        sprite.obj[props.prop2][props.prop] = props[fNew-firstKeyFr];
              } else {
                while (keyFrm<numKeyFr && fNew>=sprite.keyFrames[keyFrm]) keyFrm++;
                if (firstTime || fNew==sprite.keyFrames[keyFrm-1]) {
                  if (props.prop2 == null) sprite.obj[props.prop] = props[keyFrm-1];
                  else        sprite.obj[props.prop2][props.prop] = props[keyFrm-1];
        } } } } }
      } else if (sprite.charAt(0)=='b' && fNew == sprite.frame) eval(sprite.value);
      if (fNew > tmLn.lastFrame) tmLn.ID = 0;
  } }
}
//-->
</script>
<script language="javascript">

	$(document).ready(function(){
		$('#item_name').html('<option value=>-- Select --</option>');
		$('#item_name').css( "background-color","#F5F5F5" );
		$('#item_name').attr('disabled','disabled');
		
		var countChecked = function() {
		var n = $( "input:checked" ).length;
	//	var job = $( "jobcheck" ).value;
		//alert(job);
		  if(n==1){
			  $('#item_name').removeAttr('disabled');
			  $('#item_name').css( "background-color","" );
			  $.post('fare_frm2.php',{job_nox:$("input:checked").val()},function(data){
				  if(data=="No"){
					  $('#item_name').html('<option value=>-- No Item --</option>');
					  $('#item_name').attr('disabled','disabled');
				  }else{
					  $('#item_name').html(data);
					
					;
				  }
			  });
		  }else{
			  $('#item_name').attr('disabled','disabled');
			  $('#item_name').css( "background-color","#F5F5F5" );
		  }
		};
		//countChecked();
		 
		$( "input[type=checkbox]" ).on( "click", countChecked );
	});
</script>

<script type="text/javascript"><!--
// Returns an array with values of the selected (checked) checkboxes in "frm"
function getSelectedChbox(frm) {
 // JavaScript & jQuery Course - http://coursesweb.net/javascript/
  var selchbox = [];        // array that will store the value of selected checkboxes

  // gets all the input tags in frm, and their number
  var inpfields = frm.getElementsByTagName('input');
  var nr_inpfields = inpfields.length;

  // traverse the inpfields elements, and adds the value of selected (checked) checkbox in selchbox
  for(var i=0; i<nr_inpfields; i++) {
    if(inpfields[i].type == 'checkbox' && inpfields[i].checked == true) selchbox.push(inpfields[i].value);
  }

  return selchbox;
}

  /* Test this function */
// When click on #btntest, alert the selected values
document.getElementById('btntest').onclick = function(){
  var selchb = getSelectedChbox(this.form);     // gets the array returned by getSelectedChbox()
 // alert(selchb);
  //	url: "upload_photo_in.php?P=" + document.getElementById('job').value,
  var myWindow = window.open("upload_po.php?job_no="+selchb, "_blank", "width=600, height=600");

}
//-->
</script>
         </form>
          
          
          
          
          
    </td>

  <tr valign="top">
    <td align="center"><img src="images/buttom.jpg" width="442" height="76"  /></td>
</table>

    </td>

  </tr>
</table>
</body>

</html>




คือตอนนี้เฉพาะ code หน้านี้ของ ผมถ้า data มีหลายๆ record พบว่ามีการ query ข้อมูลนานมากเลย ประมาน 10-15 วิ /1000 record
พอจะมีวิธีแก้ไขหรือตรวจสอบสาเหตุได้มั้ยครับว่ามันเกิดจากอะไร



Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-08-28 22:48:55 By : wahahaboy View : 1336 Reply : 3
 

 

No. 1



โพสกระทู้ ( 342 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เบื้องต้น

- โครงสร้าง html ของคุณ ดูประหลาดมากครับ ไม่รู้ว่า copy เกินมา หรือเป็นแบบนี้อยู่แล้ว ประหลาดจนผมคิดว่าคุณควรจะสังคายนาโค้ดของคุณใหม่ ครั้งใหญ่เลย
- ผมขอข้ามการวิจารณ์โค้ด JS ไป
- ไม่ขอวิจารณ์ กรณี ไม่มี jobsearch
- และไม่ขอวิจารณ์ว่าโค้ดมี logic ถูกต้องหรือไม่ ซึ่งแน่นอนว่า หาก logic เพี้ยน มันกระทบต่อความเร็วแน่นอน โดยเฉพาะ กรณี loop เกินจำเป็น


ต่อไป เชิญรับฟังการวิจารณ์ และความเห็นเพิ่มเติมเล็กน้อยครับ
------------------------------

- กลุ่มคำสั่ง บรรทัด 14 ดูไม่มีประโยชน์อะไร แต่หากจะใช้ ไหนๆ จะเอาข้อมูลมาจาก session บรรทัด 6 แล้ว ก็น่าจะทำตั้งแต่แรกที่ทำ session

-บรรทัด 176 ค่ามากจาก GET (จากบรรทัดที่ 13) ขอเดาว่า ไม่ได้มาจากผู้ใช้ป้อนข้อมูลเอง อาจจะเกิดจากการคลิ๊ก หรือ redirect มา
ค่าพวกนี้ ควรเป็นค่าที่แน่นอน จัดการตัวแปรดี จัดการด้านการอินพุทดี ๆ ไม่ต้องใช้ wide search ครับ จะทำให้คุณได้ผลลัพพ์ก้อนเดียว หรือ กลุ่มที่เกี่ยวข้อง ก้อนเดียวจริงๆ
ซึ่งกรณี ไม่มีค่าพวกนี้ (ไม่มีข้อมล) จากการกวาดสายตา โค้ดคุณก็แสดงแค่ฟอร์ม( ที่โครงสร้างเพีย้น) ธรรมดาครับ

หากวิเคราะห์จากคำสั่ง เดาว่าตาราง stock ของคุณมี FK เป็น job_no ซึ่งปกติ FK เราไม่ค่อย wide search กันอยู่แล้วครับ (หรือเป็นแค่ผมคนเดียวก็ไม่รู้นะ)

- และคุณใช้ job_no ก็ควร select มาแค่ job_no ครับ

-sql ถัดมา บรรทัด 191 ผมพยายามมองแง่ดีไว้ คือ คุณเจตนาใช้ตรวจสอบค่า อันนี้ดีหน่อย ที่คุณไม่ใช่ wide search

หาก if คุณเป็นจริง

- กลุ่มคำสั่งในบรรทัด ที่ 196 คุณตรวจสอบค่าเฉยๆ (คุณใช้ wide search อีกแล้ว)

- กลุ่มคำสั่งในบรรทัดที่ 211 คุณควรมีชื่อเล่นให้มันหน่อยครับ เป็น best practice อย่างหนึ่ง และคุณแค่เช็คค่าเฉยๆ อีกเช่นกัน (และคุณ ก็ใช้ wide search อีกเช่นกัน)

หาก if คุณเป็นเท็จ

-กลุ่มคำสั่งในบรรทัดที่ 235 นั้น คุณแค่เช็คค่า ว่า "มี" รึเปล่า ถ้าไม่มี ก็เฉยๆ ไม่ทำอะไร ถ้ามีก็ทำเล็กน้อย



--สรุป--
0. ผมเห็นว่าคุณไม่มีการ "เชื่อม" ตารางใดๆ ใช้การแยกคำสั่งอย่างชัดเจน ซึ่งก็ถือเป็นเรื่องที่โอเคครับ จะมีก็แต่ subquery ที่ผมแนะนำว่า ควรมี "ชื่อเล่น" ให้มันหน่อย
1. ให้คุณปรับเงื่อนไข ให้ออกจากรูป wide search
2.select เฉพาะที่ต้องการจะใช้จริงๆ
3. ปรับโครงสร้าง html ใหม่ อันนี้ขอร้องกันจริงๆ

ปล.1
หากทำแล้ว และมั่นใจว่า logic ของโปรแกรมถูกแล้ว ไม่ดีขึ้นแต่อย่างใด
เอา index ในทุกตารางที่เกี่ยวข้อง ออกมาให้ดูอีกทีครับ
แล้วจะแสดงความคิดเห็นอีกที แล้วเดี๋ยวผมจะพา optimize กันอีกรอบ profiling กันให้ทุกคำสั่งไปเลย

ปล2. อย่าเชื่อผมมากนะครับ ผมง่วงนอน อาจจะเพี้ยนนิดหน่อย หรือเพี้ยนหมดก็ได้ รอฟังท่านอื่นอีกที

ปล3. การตั้งคำถามโดยไม่มีคำอธิบายอะไรเพิ่มเติม ไม่ใช่เรื่องดีเท่าไหร่ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-08-29 10:13:06 By : triplea
 


 

No. 2



โพสกระทู้ ( 1,636 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

WHERE job_no like '%".$data['job_no']."%' ";

ถ้า ฟีลด์ job_no เป็น ตัวเลข และ เป็น unique key (คีย์ห้ามซ้ำ) ก็ไม่ควรใช้ like '%
เพราะถ้าเป็นตัวเลขน้อย มันก็จะคิวรี่เอา ตัวเลขมากมาด้วย
เช่น เลข 1 เมื่อเจอ 1 10 11 12 201 21 31 41 2001 210 211 แบบนี้มันเอามาหมด
ดังนั้นควรใช้เจาะจง
"WHERE job_no =".$data['job_no'];


จากเหตุผลข้างบนทำให้โค๊ดข้างล่างนี้ทำงานช้ามาก บันทัดที่ 211
Code (PHP)
$sql3="SELECT st_name FROM stock ";
$sql3.="WHERE st_name NOT IN (
SELECT job_item FROM payment
WHERE job_no LIKE '%".$data['job_no']."%'
)
AND job_no LIKE '%".$data['job_no']."%' ";
เพราะคำสั่ง not in จะคิวรี่เอา %1% มาทุกตัว


ให้แก้เป็น
Code (PHP)
$sql3="SELECT st_name FROM ( 
		select st_name, job_no from stock where job_no = $data[job_no] 
	) as tmp # สร้าง temp แค่ record เดียว
	WHERE NOT exists (
			SELECT job_item FROM payment 
			WHERE job_item=tmp.st_name and job_no = tmp.job_no
		) ";


ส่วนอื่นๆ ก็ตาม คห 1 เลยครับ


ประวัติการแก้ไข
2015-08-29 11:32:17
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-08-29 11:16:48 By : NewbiePHP
 

 

No. 3



โพสกระทู้ ( 95 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณที่แนะนำครับ ผมก้เจอแล้วมันช้าที่ บรรทัด 211 จริงๆ แต่ว่า job_no ไม่ได้เป็นตัวเลข ครับ แต่เป็น primary เด่วลองแก้จาก like เป็น = ดูครับ เด่วลองแก้ดูก่อนครับ

คือของผมจะมี 3 tabale
1 job
1.1 job_no

2 stock
2.1 job_no
2.2 st_name

3 payment
3.1 job_no
3.2 item

คือผมต้องการให้หน้านี้ดึง ข้อมูลเลข job จากตารางที่ 1 โดยมีเงื่อนไขที่1 ว่า
ถ้า ใน ตารางที่3 นี้มีเลข job ตรงกับตาารางที่1 แล้วมันจะไม่ขึ้นอีก
เงื่อนไขที่2 ถ้าเกิด เลขตารางที่1 กับเลขตารางที่3 ตรงกันก้จริง แต่ในตารางที่3 มี ข้อมูลของ item มาด้วย ฉะนั้นต้อง
เอาตาราง ที่3 ข้อมูลไอเทม ไปเชคกับตารางที่2 ที่มีชื่อไอเทมอยู่ เพื่อที่ จะให้แสดงเลข job อยู่ถ้าในตารางที่2 มี3 ไอเทม แต่ในตารางที่2 ในช่องไอเทม เรามีแค่2ไอเทม เลข job ก้ยังขึ้นอยุ่จนกว่าในตารางที่3 ช่อง ไอเทม จะมีครบ เท่ากับ ตารางที่2 เลข job จะไม่ขึ้นคับ


ประวัติการแก้ไข
2015-08-30 11:53:49
2015-08-30 11:55:20
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-08-30 11:52:40 By : wahahaboy
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Code php query ข้อมูลนานมากเลย ประมาน 10-15 วิ /1000 record ช่วยหาทางแก้ทีครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่