  | 
              
	              
	                
  
    
	 
        Warning: mysql_num_rows():  รันแล้วมันขึ้นอย่างนี้ Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
               <html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"> 
<title>Untitled Document</title> 
</head> 
 
<body> 
<u>รายงาน</u> 
<form name="form1" method="post" action="800.php"> 
  <p>โกดัง 
      <input name="wareh_name" type="keyword" id="wareh_name" value="" size="15" maxlength="25"> 
    บริษัท 
    <input name="compn_name" type="keyword" id="compn_name" value="" size="15" maxlength="25"> 
    จากวันที่ 
    <input name="date1" type="text" id="date1" size="10"> 
    ถึงวันที่ 
    <input name="date2" type="text" id="date2" size="10"> 
    <input type="submit" name="Submit" value="รายงาน"> 
  </p> 
</form> 
<hr> 
<? 
mysql_connect( "localhost", "root", "newproxy") or die ("not connect database Mysql"); 
mysql_select_db("movesugar") or die("not select database"); /* ??????????????????????? */ 
$sql="SELECT  movein.mvin_date, movein.prodt_year, movein.qtys, movein.prodt_weig, movein.prodt_pol, movein.prodt_color, company.compn_name, product.prodt_name, wareh.wareh_name FROM 
           movein  left join (product, company, warehous) on (movein.prodt_code = product.prodt_code and company.compn_code = movein.compn_code and  warehous.wareh_code = movein.wareh_code) 
          where  wareh_name like '$wareh_name'  || compn_name like '$compn_name' ||  mvin_date between ( '$date1'  and  '$date2')";        
$db_query=mysql_db_query("movesugar",$sql); 
$num_rows=mysql_num_rows($db_query); /* ??? Reccord ????? */ 
if(empty($num_rows)) /* ?????????????????????? */ 
{ 
echo"<center><br>ไม่พบ    <b>$keyword</b>    จากการค้นหา </center>"; 
exit(); 
} 
else 
{ 
?> 
<div align="center"> 
<? echo "รายงาน   <b>$keyword</b>   พบ  <b>$num_rows</b>   เรคคอร์ด"; ?> 
<br> 
<br> 
</div> 
<table width="650" height="45" border="1"> 
        <!--DWLayoutTable--> 
      <tr> 
        <td width="64" height="39" align="center">วัน/เดือน/ปี</td> 
        <td width="51" align="center">สินค้า</td> 
        <td width="52" align="center">ปีผลิต</td> 
        <td width="143" align="center">จำนวน (กส.)</td> 
        <td width="152" align="center">น้ำหนัก(ตัน)</td> 
        <td width="57" align="center">ค่า Pol</td> 
        <td width="54" align="center">ค่าสี</td> 
  </tr> 
</table> 
<? 
$a=0; 
while($a < $num_rows) 
{ 
$result = mysql_fetch_array($db_query); 
$mvin_date=$result[mvin_date]; 
$product_name=$result[prodt_name]; 
$prodt_year=$result[prodt_year]; 
$prodt_qtys=$result[prodt_qtys]; 
$prodt_weig=$result[prodt_weig]; 
$prodt_pol=$result[prodt_pol]; 
$prodt_color=$result[prodt_color]; 
?> 
<table width="650" height="143" border="1"> 
        <!--DWLayoutTable--> 
      <tr> 
        <td width="64" height="101" valign="top"><? echo"$mvin_date";?></td> 
        <td width="51" align="center" valign="top"><? echo"$prodt_code";?></td> 
        <td width="52" align="center" valign="top"><? echo"$prodt_year";?></td> 
        <td width="150" align="right" valign="top"><? echo"$prodt_qtys";?></td> 
        <td width="152" align="right" valign="top"><? echo"$prodt_weig";?></td> 
        <td width="57" align="right" valign="top"><? echo"$prodt_pol";?></td> 
        <td width="54" align="right" valign="top"><? echo"$prodt)color";?></td> 
  </tr> 
      <tr> 
        <td height="34">สรุปสุทธิ</td> 
        <td> </td> 
        <td> </td> 
        <td align="right" valign="top"><!--DWLayoutEmptyCell--> </td> 
        <td align="right">NN.NNN,NNN,NNN,NNN</td> 
        <td align="right">NNN</td> 
        <td> </td> 
  </tr> 
</table> 
<? 
$a++; 
} 
} 
 
?> 
</body> 
</html>  
 
 
 
 
พอรันแล้วมันขึ้นอย่างนี้ 
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\movesugar\movesugar\800.php on line 29 
 
  Tag : - - - -              
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          4 ธ.ค. 2550  13:48:48 | 
                      By :
                          11 | 
                      View :
                          1807 | 
                      Reply :
                          11 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                $sql="SELECT movein.mvin_date, movein.prodt_year, movein.qtys, movein.prodt_weig, movein.prodt_pol, movein.prodt_color, company.compn_name, product.prodt_name, wareh.wareh_name FROM 
movein left join (product, company, warehous) on (movein.prodt_code = product.prodt_code and company.compn_code = movein.compn_code and warehous.wareh_code = movein.wareh_code) 
where wareh_name like '$wareh_name' || compn_name like '$compn_name' || mvin_date between ( '$date1' and '$date2')";  
 
 
 
น่าจะผิดที่ sql ลอง check ดูอีกที 
หรือ 
 
ลองเปลี่ยน || เป็น or    
 
และ between ( '$date1' and '$date2')";  เป็น between  '$date1' and '$date2' ";  
 
                          
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  14:00:26 | 
                        By :
                            tacomsci | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ไม่ได้อ่ะ error เหมือนเดิมเลย                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  14:19:53 | 
                        By :
                            11 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                $sql="SELECT movein.mvin_date, movein.prodt_year, movein.qtys, movein.prodt_weig, movein.prodt_pol, movein.prodt_color, company.compn_name, product.prodt_name, *wareh.wareh_name FROM 
movein left join (product, company, warehous) on (movein.prodt_code = product.prodt_code and company.compn_code = movein.compn_code and warehous.wareh_code = movein.wareh_code) 
where *wareh_name like '$wareh_name' || *compn_name like '$compn_name' || *mvin_date between ( '$date1' and '$date2')";  
  
 
ลองเช็คชื่อฟิลด์ตรงทีทำเครื่องหมาย* นะคะ แล้วตรงหลัง where ลองใส่ ชื่อtable.ชื่อฟิลด์ ดูอะ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  14:32:17 | 
                        By :
                            hobbits | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                เอ้อ พิมพ์ผิดนิดนึง ตรง wareh.wareh_name ชื่อ table มันเปง warehous อะนะ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  14:33:42 | 
                        By :
                            hobbits | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                error  อีกแล้ว  เหมือนเดิมน่ะ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  14:40:21 | 
                        By :
                            11 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                like '$wareh_name' || compn_name like '$compn_name'  
 
ถ้าใช้แบบนี้ มันจะต้องตรงเป๊ะๆ ถึงจะออกนะ 
 
ลองแบบนี้ 
 
like '%$wareh_name%' || compn_name like '%$compn_name%'  
 
                            
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  15:59:53 | 
                        By :
                            lozomac | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ขอบคุณทุกคนนะ แต่ยังเหมือนเดิมอ่ะ เฮ้อ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            4 ธ.ค. 2550  16:25:50 | 
                        By :
                            11 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ข้องเขียน sql ให้รัดกุมกว่านี้หน่อยนะครับ ถ้ามีเงื่อนไขเยอะก็ควรจะมีวงเล็บครอบบ้าง และก็เวลาที่ join ก็ต้องระบุ ชื่อตารางแล้วจุดก่อน ด้วยนะครับ     เช่น  
... where  (person.id=1) or (department.id=5) 
 
ส่วนโปรแกรมของคุณไม่ได้ผิดที่ตรงไหนนอกจาก SQL เรียกข้อมูลออกมาไม่ได้เนื่องจาก sql  ที่คุณเขียน มันไม่สามารถแสดงข้อมูลที่ต้องการออกมาได้เท่านั้นเอง   
 
เวลาที่ join ใน mysql นะครับ ต้องตรวจก่อน นะครับ เพราะมันไม่มี auto-compelete ให้นะ tool ของ mysql 
 
 
ไม่ได้โค้ดให้ แต่คิดว่าน่าจะได้แนวแก้ไขนะครับ 
                                      
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            5 ธ.ค. 2550  21:44:08 | 
                        By :
                            ravatna | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ลองทำแล้วแต่ไม่ได้เหมือนเดิมอ่ะ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            7 ธ.ค. 2550  09:37:34 | 
                        By :
                            11 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ลอง SELECT ที่ละตารางดูก่อน แล้วค่อย join ที่ละตาราง ไม่ควร join ที่เดียวหลายตารางอ่ะ เมื่อเกิด errer แล้ว จะแก้ใขลำบาก ค่อยเป็นค่อยไป สู้ๆ                           
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            7 ธ.ค. 2550  14:56:55 | 
                        By :
                            heng | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                ได้แล้วค่ะ ขอบคุณทุกคนนะคะ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            8 ธ.ค. 2550  10:37:58 | 
                        By :
                            11 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |