  | 
              
	              
	                
  
    
	 
        ปรึกษาเกี่ยวกับการจะรวมตัวแปร PHP หลายๆตัว ให้เป็น $message ตัวแปรข้อความตัวเดียว ได้อย่างไร     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                จะรวมตัวแปร PHP หลายๆตัว ให้เป็น $message ตัวเดียวอย่างไร โดยที่ตัวแปร อยู่นอกลูป While โดยรูปแบบที่แสดงข้อความเป็นแบบตามรูป จะต้องทำอย่างไรครับ 
  
 
ตารางฐานข้อมูล 
  
  
 
 
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" />
		<meta charset="UTF-8">
		<title> ตารางการประชุม </title>
		<script language="JavaScript" type="text/javascript">
			function sivamtime() {
			now=new Date();
			hour=now.getHours();
			min=now.getMinutes();
			sec=now.getSeconds();
			if (min<=9) { min="0"+min; }
			if (sec<=9) { sec="0"+sec; }
			//if (hour>12) { hour=hour-12; add="PM"; }
			// else { hour=hour; add="AM"; }
			// if (hour==12) { add="PM"; }
			// time = ((hour<=9) ? "0"+hour : hour) + ":" + min + ":" + sec + " " + add;
			add = "น.";
			time = hour + ":" + min + " " + add;
			if (document.getElementById) { theTime.innerHTML = time; }
			else if (document.layers) {
			document.layers.theTime.document.write(time);
			document.layers.theTime.document.close(); }
			setTimeout("sivamtime()", 1000);
			}
			window.onload = sivamtime;
		</script>
	</head>
	<body>
				<p>
				  <?php
					include('common/connect_db.php');
					date_default_timezone_set('asia/bangkok');
					function ThaiDate()
					{
						$ThMonth = array ( "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.",
						"พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.",
						"ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค." );
						$a = date( "w" ); // ค่าวันในสัปดาห์ (0-6)
						$b = date( "n" )-1; // ค่าเดือน (1-12)
						$c = date( "j" ); // ค่าวันที่(1-31)
						$d = date( "Y" )+543; // ค่า ค.ศ.บวก 543 ทำให้เป็น ค.ศ.
						return "$c-$ThMonth[$b]-$d";
					}
					echo $days="รายการวันนี้ ".thaidate(); // พิมพ์วันที่
					$uptime=date('H:i');
					$vardate=date('Y-m-d');?>
				  <?php
			$loc_arr = array(20);
			$i=0;
			$objConnect = mysql_connect("localhost","root","root");
			$dbname = mysql_select_db("project");
			$sql = "SELECT r.s_date AS sdate, r.e_date AS edate, r.meeting_desc AS mt, l.location AS loc , l.location_id AS loc_id
					FROM meeting_reserve AS r JOIN meeting_location AS l ON l.location_id = r.location_id
					WHERE r.s_date LIKE '%$vardate%' ORDER BY l.location_id ASC, r.s_date ASC";
			$query = mysql_query($sql) or die ("Error[".$sql."]");
			?>
				  <?php echo $time= " @เวลา".$uptime."</br>";
			 		while($show = mysql_fetch_array($query)){ 
					$loc_arr[$i] = $show['loc_id'];
						if($i != 0) {  
										if($loc_arr[$i] != $loc_arr[$i-1])
											{ echo $show['loc'].'</br>';}
										} 
										else if($i == 0)
											{  echo $show['loc'].'</br>';} 
										$i++;
					$sdate=substr($show['sdate'],11,5);
					$edate=substr($show['edate'],11,5);
					$showtext=$show['mt'];
					echo $title=$sdate.'-'.$edate.'_'.$showtext."</br>"; 
					}
					$message=$days.$time;
				  ?>
	</body>
</html>
 
 
  Tag : PHP, MySQL, HTML, CSS               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-12-05 11:57:51 | 
                      By :
                          bb | 
                      View :
                          1486 | 
                      Reply :
                          9 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
$msg='';
while($ro = ...){
   $msg.=$ro['xxxxx'].'<br>'.;
}
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-12-05 14:53:24 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ไม่รู้ว่าผมเข้าใจเจตนารมย์ จขกท. ถูกหรือเปล่านะครับ 
 
ก็แค่เอา $message = $days.$time; ไปไว้บน while Loop จากนั้นก็เอาตัวแปร $message ไปไว้ใน Loop ครับ แล้วยัดค่าต่อสตริงไปทีละแถว 
 
<!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" />
		<meta charset="UTF-8">
		<title> ตารางการประชุม </title>
		<script language="JavaScript" type="text/javascript">
			function sivamtime() {
			now=new Date();
			hour=now.getHours();
			min=now.getMinutes();
			sec=now.getSeconds();
			if (min<=9) { min="0"+min; }
			if (sec<=9) { sec="0"+sec; }
			//if (hour>12) { hour=hour-12; add="PM"; }
			// else { hour=hour; add="AM"; }
			// if (hour==12) { add="PM"; }
			// time = ((hour<=9) ? "0"+hour : hour) + ":" + min + ":" + sec + " " + add;
			add = "น.";
			time = hour + ":" + min + " " + add;
			if (document.getElementById) { theTime.innerHTML = time; }
			else if (document.layers) {
			document.layers.theTime.document.write(time);
			document.layers.theTime.document.close(); }
			setTimeout("sivamtime()", 1000);
			}
			window.onload = sivamtime;
		</script>
	</head>
	<body>
				<p>
				  <?php
					include('common/connect_db.php');
					date_default_timezone_set('asia/bangkok');
					function ThaiDate()
					{
						$ThMonth = array ( "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.",
						"พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.",
						"ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค." );
						$a = date( "w" ); // ค่าวันในสัปดาห์ (0-6)
						$b = date( "n" )-1; // ค่าเดือน (1-12)
						$c = date( "j" ); // ค่าวันที่(1-31)
						$d = date( "Y" )+543; // ค่า ค.ศ.บวก 543 ทำให้เป็น ค.ศ.
						return "$c-$ThMonth[$b]-$d";
					}
					echo $days="รายการวันนี้ ".thaidate(); // พิมพ์วันที่
					$uptime=date('H:i');
					$vardate=date('Y-m-d');?>
				  <?php
			$loc_arr = array(20);
			$i=0;
			$objConnect = mysql_connect("localhost","root","root");
			$dbname = mysql_select_db("project");
			$sql = "SELECT r.s_date AS sdate, r.e_date AS edate, r.meeting_desc AS mt, l.location AS loc , l.location_id AS loc_id
					FROM meeting_reserve AS r JOIN meeting_location AS l ON l.location_id = r.location_id
					WHERE r.s_date LIKE '%$vardate%' ORDER BY l.location_id ASC, r.s_date ASC";
			$query = mysql_query($sql) or die ("Error[".$sql."]");
			?>
				  <?php echo $time= " @เวลา".$uptime."</br>";
				  
				  $message = $days.$time;
				  
			 		while($show = mysql_fetch_array($query)){ 
					$loc_arr[$i] = $show['loc_id'];
						if($i != 0) {  
										if($loc_arr[$i] != $loc_arr[$i-1])
											{ echo $show['loc'].'</br>';}
										} 
										else if($i == 0)
											{  echo $show['loc'].'</br>';} 
										$i++;
					$sdate=substr($show['sdate'],11,5);
					$edate=substr($show['edate'],11,5);
					$showtext=$show['mt'];
					echo $title=$sdate.'-'.$edate.'_'.$showtext."</br>"; 
					$message .= $title;
					}
				  ?>
	</body>
</html>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-12-05 15:03:46 | 
                        By :
                            tomrambo | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 แล้วได้ลองนำโค้ดที่ผมโพสต์ไปลองรันดูหรือยังครับ ได้ผลลัพธ์ตามที่ต้องการหรือเปล่าครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-12-05 17:13:51 | 
                        By :
                            tomrambo | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 echo $message; นอก while Loop สิครับ ถ้า echo ใน Loop วันที่ก็จะวนซ้ำ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-12-05 18:13:15 | 
                        By :
                            tomrambo | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 8 เขียนโดย : tomrambo เมื่อวันที่ 2017-12-05 18:13:15 
รายละเอียดของการตอบ ::
  ได้แล้วครับ ขอบพระคุณมากครับ   
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" />
		<meta charset="UTF-8">
		<title> ตารางการประชุม </title>
		<script language="JavaScript" type="text/javascript">
			function sivamtime() {
			now=new Date();
			hour=now.getHours();
			min=now.getMinutes();
			sec=now.getSeconds();
			if (min<=9) { min="0"+min; }
			if (sec<=9) { sec="0"+sec; }
			add = "น.";
			time = hour + ":" + min + " " + add;
			if (document.getElementById) { theTime.innerHTML = time; }
			else if (document.layers) {
			document.layers.theTime.document.write(time);
			document.layers.theTime.document.close(); }
			setTimeout("sivamtime()", 1000);
			}
			window.onload = sivamtime;
		</script>
	</head>
	<body>
				<p>
				  <?php
					include('common/connect_db.php');
					date_default_timezone_set('asia/bangkok');
					function ThaiDate()
					{
						$ThMonth = array ( "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.",
						"พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.",
						"ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค." );
						$a = date( "w" ); // ค่าวันในสัปดาห์ (0-6)
						$b = date( "n" )-1; // ค่าเดือน (1-12)
						$c = date( "j" ); // ค่าวันที่(1-31)
						$d = date( "Y" )+543; // ค่า ค.ศ.บวก 543 ทำให้เป็น ค.ศ.
						return "$c-$ThMonth[$b]-$d";
					}
					 $days="รายการวันนี้ ".thaidate(); // พิมพ์วันที่
					$uptime=date('H:i');
					$vardate=date('Y-m-d');?>
				  <?php
			$loc_arr = array(20);
			$i=0;
			$objConnect = mysql_connect("localhost","root","root");
			$dbname = mysql_select_db("project");
			$sql = "SELECT r.s_date AS sdate, r.e_date AS edate, r.meeting_desc AS mt, l.location AS loc , l.location_id AS loc_id
					FROM meeting_reserve AS r JOIN meeting_location AS l ON l.location_id = r.location_id
					WHERE r.s_date LIKE '%$vardate%' ORDER BY l.location_id ASC, r.s_date ASC";
			$query = mysql_query($sql) or die ("Error[".$sql."]");
			?>
				  <?php  $time= " @เวลา".$uptime."</br>";
				  
				  $message = $days.$time;
				  
			 		while($show = mysql_fetch_array($query)){ 
					$loc_arr[$i] = $show['loc_id'];
							 if($i != 0) {  
										if($loc_arr[$i] != $loc_arr[$i-1])
											{  $message.=$show['loc'].'</br>';}
										} 
										else if($i == 0)
											{  $message.=$show['loc'].'</br>';} 
										$i++;
					$sdate=substr($show['sdate'],11,5);
					$edate=substr($show['edate'],11,5);
					$showtext=$show['mt'];
					 $title=$sdate.'-'.$edate.'_'.$showtext."</br>"; 
					 $message .= $title;
					}
					echo $message ;
				  ?>
	</body>
</html>
                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2017-12-05 19:20:42 2017-12-05 19:28:24 2017-12-05 19:29:17              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-12-05 19:19:29 | 
                        By :
                            bumrungkij | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ประมาณนี้ครับ 
 
<!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" />
		<meta charset="UTF-8">
		<title> ตารางการประชุม </title>
		<script language="JavaScript" type="text/javascript">
			function sivamtime() {
			now=new Date();
			hour=now.getHours();
			min=now.getMinutes();
			sec=now.getSeconds();
			if (min<=9) { min="0"+min; }
			if (sec<=9) { sec="0"+sec; }
			add = "น.";
			time = hour + ":" + min + " " + add;
			if (document.getElementById) { theTime.innerHTML = time; }
			else if (document.layers) {
			document.layers.theTime.document.write(time);
			document.layers.theTime.document.close(); }
			setTimeout("sivamtime()", 1000);
			}
			window.onload = sivamtime;
		</script>
	</head>
	<body>
				<p>
				  <?php
					include('common/connect_db.php');
					date_default_timezone_set('asia/bangkok');
					function ThaiDate()
					{
						$ThMonth = array ( "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.",
						"พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.",
						"ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค." );
						$a = date( "w" ); // ค่าวันในสัปดาห์ (0-6)
						$b = date( "n" )-1; // ค่าเดือน (1-12)
						$c = date( "j" ); // ค่าวันที่(1-31)
						$d = date( "Y" )+543; // ค่า ค.ศ.บวก 543 ทำให้เป็น ค.ศ.
						return "$c-$ThMonth[$b]-$d";
					}
					 $days="รายการวันนี้ ".thaidate(); // พิมพ์วันที่
					$uptime=date('H:i');
					$vardate=date('Y-m-d');?>
				  <?php
			$objConnect = mysql_connect("localhost","root","root");
			$dbname = mysql_select_db("project");
			$sql = "SELECT r.s_date AS sdate, r.e_date AS edate, r.meeting_desc AS mt, l.location AS loc , l.location_id AS loc_id
					FROM meeting_reserve AS r JOIN meeting_location AS l ON l.location_id = r.location_id
					WHERE r.s_date LIKE '%$vardate%' ORDER BY l.location_id ASC, r.s_date ASC";
			$query = mysql_query($sql) or die ("Error[".$sql."]");
			?>
				  <?php  $time= " @เวลา".$uptime."</br>";
				  
				  $message = $days.$time;
				  $locate_id = '';
				  
			 		while($show = mysql_fetch_array($query)){ 
					
					if($show['loc_id'] != $locate_id){
						
						$message .= $show['loc']."</br>";
						$locate_id = $show['loc_id'];
						
					}
					
					$sdate=substr($show['sdate'],11,5);
					$edate=substr($show['edate'],11,5);
					$showtext=$show['mt'];
					 $title=$sdate.'-'.$edate.'_'.$showtext."</br>"; 
					 $message .= $title;
					}
					echo $message ;
				  ?>
	</body>
</html>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-12-05 19:47:42 | 
                        By :
                            tomrambo | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |