  | 
              
	              
	                
  
    
	 
        อยากถามระบบเมนู คือว่าผมทำระบบเมนูที่ดึงมาจากฐานข้อมูลโดยจะมีดังนี้ ฐานข้อมูลเมนู     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                คือว่าผมทำระบบเมนูที่ดึงมาจากฐานข้อมูลโดยจะมีดังนี้ 
ฐานข้อมูลเมนู 
id_menu 
name_menu 
 
นี้เมนูที่บันทึก 
1=IT 
2=monitor 
3=mainboard 
****************************** 
ฐานข้อมูลproduck 
id_pro,id_menu,detile,pic 
ข้อมูลที่บันทึก 
1,1,จอภาพราคาประหยัด,motitor 
2,2,เมนบอร์ดราคาประหยัด,m 
3,1,จอภาพราคาประหยัด,motitor 
4,2,เมนบอร์ดราคาประหยัด,m 
********************************* 
ตรงหน้าแสดงเมนูคือว่าอยากคลิกลิ้งค์แล้วให้แสดงเฉพาะหัวข้อนั้นแต่ให้แสดงในหน้า index เท่านั้น 
ตอนที่ทำแบบเมนูธรรมดาผมต้องมาสร้างไฟล์งานหลายอันเพื่อที่จะให้แสดงตามหัวขอแต่ละประเภท 
ก็เลยอยากลองทำแบบดึงมาจากฐานข้อมูลดูอ่ะครับ 
งงกับคำถามหรือเปล่าครับ
 
 
  Tag : - - - -              
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2009-08-27 10:41:42 | 
                      By :
                          somparn | 
                      View :
                          1411 | 
                      Reply :
                          4 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 หมายถึง เลือกเมนู IT แล้วให้แสดงหัวข้อ ที่เป็นข้อมูลที่เป้น IT หรือเปล่าครับ ?? 
 
ลองรับค่าจากเมนู  แล้ว ส่งค่ากลับให้หน้า index  Select ข้องมูลตามค่าที่ส่งมา.. 
 
 
 
ไม่รู้ว่าต้องการแบบนี้หรือป่าว หรืออาจจะมี ท่านอื่นที่มีความคิดดีๆ กว่านี้นะครับ                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-08-27 11:21:23 | 
                        By :
                            peak_z | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 [color=pink][/color             ผมเด็กมีปันหา                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-12-02 14:50:40 | 
                        By :
                            0871124864 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 inc_conn.php 
 
Code (PHP) 
<?
$dbuser = "root";
$dbpasswd = "root";
$servername = "localhost";
$dbname ="cms";
$conn = mysql_connect($servername,$dbuser,$dbpasswd);
mysql_query("SET collation_connection = 'uft8 ");
    if (!$conn){
		exit("Could not connect: " . mysql_error());
    }else{
		$dbconn = mysql_select_db($dbname);
		mysql_query("SET character_set_results=utf8");
		if (!$dbconn){
		  exit("Could not connect database: " . mysql_error());
		}
    }
?>
 
 
Code (PHP) 
-- 
-- Database: `cms`
-- Table structure for table `product`
-- 
CREATE TABLE `product` (
  `pro_id` int(11) NOT NULL auto_increment,
  `menu_id` int(11) NOT NULL,
  `detail` varchar(100) collate utf8_unicode_ci NOT NULL,
  `pic` varchar(30) collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`pro_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
-- 
-- Dumping data for table `product`
-- 
INSERT INTO `product` VALUES (1, 1, 'จอภาพราคาประหยัด', 'motitor');
INSERT INTO `product` VALUES (2, 2, 'เมนบอร์ดราคาประหยัด', 'm');
INSERT INTO `product` VALUES (3, 1, 'พาวเวอร์ ซัพพลาย', 'powersupply');
INSERT INTO `product` VALUES (4, 2, 'ดินสอ', 'ดินสอ');
INSERT INTO `product` VALUES (5, 3, 'ไม่รู้ไม่ชี้ คริๆ', 'ม');
  
 
 
index.php 
Code (PHP) 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table border="1" width="500px">
	<tr>
		<td width="150px">
		Main Menu <br/>
<?php
		include "inc_conn.php";
	    $sql_menu= " select  menu_id, menu_name from menu ";
		$result_menu = mysql_query($sql_menu);
		while($row = mysql_fetch_array($result_menu,MYSQL_BOTH)){
			echo "<a href='index.php?menu=".$row['menu_id']."'>".$row["menu_name"]."</a>";
			echo "<br>";
		}
		
?>
		</td>
		<td valign="top">
		Product สัมพันธ์กับเมนู <br/>
		<?php
		if((!isset($_GET['menu'])) or ($_GET['menu'] == "")){
			$menu = 1;		
		}else{
			$menu = $_GET['menu'];
		}
		
		$sql_result = " select  m.menu_id, m.menu_name, p.pro_id, p.detail, p.pic from menu as m ";
		$sql_result .= "inner join  product as p on (m.menu_id=p.menu_id) and (m.menu_id = '$menu')";
		$result = mysql_query($sql_result);
		while($show = mysql_fetch_array($result,MYSQL_BOTH)){
			echo "<a href='index.php?menu=".$show['menu_id']."&product_id=".$show['pro_id']."'>".$show["detail"]."</a>";
			echo "<br>";
		}
?>
</td>
</tr>
</table>
</body>
</html>
 
 
ลองเอาไป run ดูนะครับพี่ phpbasic                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-12-03 00:24:28 | 
                        By :
                            peterxp | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |