| 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ไม่ทราบว่าต้องการแสดงข้อมูลให้อยู่ในตารางหรือป่าวครับ ไม่รู้ตรงหรือป่าวครับพอดีรูปมันเล็ยเกินไปครับ 
 Code (PHP)
 
 <?php
	$sql = "select * from table_name order by id desc";
		$result = mysql_query($sql) 
			  or die("Error : $sql");		  
	$numrow = mysql_num_rows($result);
  for ($i=1;$i<=$numrow;$i++){
	$row = mysql_fetch_array($result);
  <tr>
    <td><?php echo $row["id"] ?></td>
  </tr>
}
?>
 ปล.มี code html ปนอยู่ด้วยน่ะครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-27 21:21:33 | By :
                            kanchen |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เราลองแล้วอ่ะ มันจะเป็นแถวเรียงยาวลงไป แต่ทีนี้ปัญหาของเรามีอยู่ว่า ยกตัวอย่างเช่น
 
 Date                                           Site A                Site B                    Site C
 q'ty     price        q'ty     price            q'ty    price
 10-02-2009               10       2.50         50       1.35            45     0.50
 30-03-2009               15       1.00         30       1.32             50    1.00
 
 ส่วนข้อมูลใน Table มันจะเป็นข้อมูลรวมทั้งหมดใน Table เดียว
 ต้องเขียนยังไงให้มันออกมาเป็นแบบตัวอย่างค่ะ??
 
 
  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-28 13:55:38 | By :
                            paphun |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | งงๆ ขอดูโครงสร้างตาราง หน่อยค่ะ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-28 15:35:02 | By :
                            tacomsci |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ตัวอย่างรายงาน 
  ตัวอย่าง Table A
 Date
 Q'ty
 Price
 Site
 
 
 คำถาม
 1. เราจะออก Report ยังไง ให้เหมือนกับ ตัวอย่างรายงานข้างบนค่ะ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-28 15:58:08 | By :
                            paphun |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ต้องการให้ข้อมูลอยู่ในตารางหรือป่าวครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-28 23:23:03 | By :
                            kanchen |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ใช่ค่ะ ต้องการให้ข้อมูลอยู่ในตาราง... เราทำมา 2 วันล่ะ ยังเครียดอยู่เลยอ่ะ ช่วยทีนะ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-29 08:43:49 | By :
                            paphun |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | <td><?php echo $row["id"] ?> เป็นการ echo ข้อมูลจาก database ครับ อันเดียวกับที่ผมเขียนให้คุณครั้งที่แล้วไงครับ แต่ต้องเขียนเพิ่มอีกนิดหน่อยนะครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-29 14:31:39 | By :
                            kanchen |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ตอนนี้ใช้ for อยู่ค่ะ แต่ไมข้อมูลที่ไม่มีมันไม่แสดงเลยอ่ะค่ะ... 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-29 15:44:38 | By :
                            paphun |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 <table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td rowspan="2">month</td>
    <td colspan="2">site A</td>
    <td colspan="2">site B</td>
    <td colspan="2">site C</td>
    <td colspan="2">site D</td>
  </tr>
  <tr>
    <td>qty</td>
    <td>price</td>
    <td>qty</td>
    <td>price</td>
    <td>qty</td>
    <td>price</td>
    <td>qty</td>
    <td>price</td>
  </tr>
  <?
  include("connect.php");
  $sql = "SELECT `ddate` , sum( qty ) AS qty, sum( `price` )  as price, site FROM `test` GROUP BY ddate, site";
  $result = mysql_query($sql);
  $old_month = "01"; // เดือนเริ่มต้น ซึ่งน่าจะเริ่มจาก 1
  $current_month = "00";
  $price =0;
  $count = 0;
  $td = array(
  "A"=>"<td> </td> <td> </td>",
  "B"=>"<td> </td> <td> </td>",
  "C"=>"<td> </td> <td> </td>",
  "D"=>"<td> </td> <td> </td>");
  $isdup = false;
  $date = "";
  while($record = mysql_fetch_array($result))
  {
		$current_month = substr($record["ddate"],5,2);
		$price = $record["price"];
		$site = $record["site"];
		$qty = $record["qty"];
		$td["$site"] = "<td>$qty</td> <td>$price</td>";
		$date = $old_month;
	  if($current_month != $old_month)
	  {
			if(!$isdup) {	$date = $current_month; }	  
			echo "<tr><td>".$date." $isdup</td>".implode(" ",$td )."</tr>";
		  $td = array(
		  "A"=>"<td> </td> <td> </td>",
		  "B"=>"<td> </td> <td> </td>",
		  "C"=>"<td> </td> <td> </td>",
		  "D"=>"<td> </td> <td> </td>");
			echo "\n";	
		if($isdup)
		{
			$date = $current_month;
			 $td["$site"] = "<td>$qty</td> <td>$price</td>";
			echo "<tr><td>".$date." $isdup</td>".implode(" ",$td )."</tr>";
			  $td = array(
			  "A"=>"<td> </td> <td> </td>",
			  "B"=>"<td> </td> <td> </td>",
			  "C"=>"<td> </td> <td> </td>",
			  "D"=>"<td> </td> <td> </td>");
			echo "\n";
			$isdup = false;
		}	
	  }else
	  {
			$isdup = true;
	  }
	  $old_month = $current_month;
	  $count++;
  }
  ?>
 </table>
 ข้อมูลที่ใช้ทดสอบ บน mysql
 
 
 
 CREATE TABLE `test` (`id` int(11) NOT NULL auto_increment,
 `ddate` date NOT NULL,
 `qty` varchar(5) NOT NULL,
 `price` varchar(5) NOT NULL,
 `site` varchar(5) NOT NULL,
 PRIMARY KEY  (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;
 
 --
 -- dump ตาราง `test`
 --
 
 INSERT INTO `test` VALUES (1, '2009-01-29', '2', '100', 'A');
 INSERT INTO `test` VALUES (2, '2009-01-29', '2', '100', 'B');
 INSERT INTO `test` VALUES (3, '2009-01-29', '2', '100', 'C');
 INSERT INTO `test` VALUES (4, '2009-01-29', '2', '100', 'D');
 INSERT INTO `test` VALUES (5, '2009-01-29', '2', '100', 'A');
 INSERT INTO `test` VALUES (6, '2009-05-29', '2', '100', 'B');
 INSERT INTO `test` VALUES (7, '2009-06-29', '2', '100', 'C');
 INSERT INTO `test` VALUES (8, '2009-07-29', '2', '100', 'D');
 INSERT INTO `test` VALUES (9, '2009-08-29', '2', '100', 'A');
 INSERT INTO `test` VALUES (10, '2009-09-29', '2', '100', 'B');
 
 สงสัย ตรงไหน โพสไว้ล่ะกันครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-29 19:52:09 | By :
                            lozomac |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ขอบใจนะจ๊ะ บักหลา  
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2009-04-30 14:44:32 | By :
                            paphun |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |