Server Side/PHP

while 대신 for 로 갯수 제한해서 뽑기

Dev. Tool 2017. 4. 1. 20:45
 $query = $mysqli_connect->query("select * from A_테이블 a left join B_테이블 b on a.locate = b.locate where a.no = '".$mysqli_connect->real_escape_string($no)."' order by b.no desc");
 
 $variables = array(); 
 
 while($print = $query->fetch_object()){ 
 
 	echo $print->name; // 원하는 출력 
 	$variables[] = $print; 
 
 }   
 
 foreach($variables as $key => $print){ 
 
 	print_r($print); 
 
 }  //////////////////////  
 
 for($i=0; $print = $query->fetch_object(); $i++){     
 	if($i==0){         
 		echo $print->name;     
 	}     
 
	 $variables[] = $print; 
 }