티스토리 뷰

(2021.08.20 본인 네이버 블로그에서 작성한 글 옮겨옴)

 

8월 6일에 썼지만

8월 20일에 올리는 지옥의 갤러리 만들기

​^_^;;;;;;;;

퇴근 1시간59분 전

째깍째깍,,,,,,,,,,,,,,,,,,,,,,,


오늘의 결과물 스포

현재 기준 이전달을 누르면 7월의 사진이 뜨고 , 또 이전달을 누르면 6월달이 나오고 ,,,,,

이렇게 달력에서처럼 바로 이전달꺼 누르고 다음달꺼 누르고 그런식...!

1. 갤러리 테이블 상태

현재 : 8월 기준으로

- 7월달꺼 (이전달)

- 다음달 (다음달 사진은 아직 없기때문에 눌러도 뜨지않음)

- 1~6월도 강제로 넣을 예정

2. img_select(test).class

<?

class select_img {
	/* DB 접속 정보 */
	var $host   = 'localhost';  // 데이터베이스 서버 주소
	var $myUser = 'jeongeum';        // 데이터베이스 사용자 ID
	var $myPw   = '1202';  // 데이터베이스 사용자 PASSWD
	var $myDb   = 'test_db';    // 데이터베이스 명
	
	var $path;
	var $name;
	var $aa = "";
	var $conn;
	var $sql;
	var $result;
	
	function select() {
         $this->conn = mysqli_connect($this->host, $this->myUser, $this->myPw, $this->myDb);

        if (!$this->conn || mysqli_error($this->conn))
		{
			die ('could not connect');
		}
		
		$this->sql = "SELECT img_ym,
                   img_name,
                   img_path											  
                       FROM gallery 
			           where date_format(img_ym,'%m') = month(now())";//현재 달 사진 출력
			
			 $this->result = mysqli_query($this->conn,$this->sql);
			
			if (mysqli_num_rows($this->result) > 0)
			{
		      while($row = mysqli_fetch_assoc($this->result))
		      { 
		        $this->path = $row['img_path'];
		        $this->name = $row['img_name'];
		        $this->aa .="<li><img src='$this->path//$this->name'></li>";
		        
		      }return $this->aa;
	        }
	        else
	        {
		     echo "테이블에 데이터가 없습니다.";
	        }
			mysqli_close($this->conn);
	}
	
	function last_month() {
		$this->conn = mysqli_connect($this->host, $this->myUser, $this->myPw, $this->myDb);

        if (!$this->conn || mysqli_error($this->conn))
		{
			die ('could not connect');
		}
		
		$this->sql = "SELECT img_ym,
                   img_name,
                   img_path											  
                       FROM gallery 
			           where date_format(img_ym,'%m') = month(now()- interval 1 month)";//이전달 사진 출력
			
			 $this->result = mysqli_query($this->conn,$this->sql);
			
			if (mysqli_num_rows($this->result) > 0)
			{
		      while($row = mysqli_fetch_assoc($this->result))
		      { 
		        $this->path = $row['img_path'];
		        $this->name = $row['img_name'];
		        $this->aa .="<li><img src='$this->path//$this->name'></li>";
		        
		      }return $this->aa;
	        }
	        else
	        {
		     echo "테이블에 데이터가 없습니다.";
	        }
			mysqli_close($this->conn);
	}
	
	function next_month() {
		$this->conn = mysqli_connect($this->host, $this->myUser, $this->myPw, $this->myDb);

        if (!$this->conn || mysqli_error($this->conn))
		{
			die ('could not connect');
		}
		
		$this->sql = "SELECT img_ym,
                   img_name,
                   img_path											  
                       FROM gallery 
			           where date_format(img_ym,'%m') = month(now()+ interval 1 month)";//다음달 사진 출력
			
			 $this->result = mysqli_query($this->conn,$this->sql);
			
			if (mysqli_num_rows($this->result) > 0)
			{
		      while($row = mysqli_fetch_assoc($this->result))
		      { 
		        $this->path = $row['img_path'];
		        $this->name = $row['img_name'];
		        $this->aa .="<li><img src='$this->path//$this->name'></li>";
		        
		      }return $this->aa;
	        }
	        else
	        {
		     echo "테이블에 데이터가 없습니다.";
	        }
			mysqli_close($this->conn);
	}
	
} 

 ?>

3. html

이전달 다음달 버튼 만듦.

main.php 요렇게

이어서 ....

댓글