everyday com-eat
작성일
2022. 5. 26. 16:57
작성자
갱수터
728x90

이상과 현실...

 

테이블 구조

 

<!Doctype html>
<html>
	<head>
		<title>식단</title>
		<link rel="styleSheet" href="resources/style.css">
	</head>
	<body>
		<?php
    		$host = 'localhost';
    		$user = '';
    		$pw = '';
    		$dbName = '';
    		
    		$conn = new mysqli($host, $user, $pw, $dbName);
    		
    		/* DB 연결 확인
    		if($conn){ echo "DB 연결 성공"."<br>"; }
    		else{ die( 'DB 연결 실패: ' . mysqli_error($conn) ); } */
    		
    		$today = date("Y-m-d");
    		
    		/* select */
    		$sql = "select * from diet where date='".$today."'";
    		$result = mysqli_query($conn, $sql);
    		
    	   
    		echo "<table border='1'><caption>오늘의 식단</caption>";
    		while($row = mysqli_fetch_array($result)){
    		    echo "<tr><th scope='row'>".$row['cate']."</th><td>";
    		    
    		    $foodArr = explode(',', $row['food']);
    		    foreach ($foodArr as $food){
    		        echo $food."<br>";
    		    }
    		    
    		    echo "</td></tr>";
    		}
        ?>
	</body>
</html>

 

 

 

 

 

날짜별 합쳐진 테이블로 다시 짜봄

 

 

<!Doctype html>
<html>
	<head>
		<title>식단</title>
		<style type="text/css">
		  table{
            display:flex;
            display: -webkit-box;
            display: -ms-flexbox;
            overflow-x: auto;
            overflow-y: hidden;
            }
        
            tbody{
                display:flex
            }
            
            th,td{display:block;}
            td {height: 180px;}
            
            thead th {
                height: 180px;
            }
            thead th:first-child {
                height: 20px;
            }
		</style>
	</head>
	<body>
		<?php
    		$host = 'localhost';
    		$user = '';
    		$pw = '';
    		$dbName = '';
    		
    		$conn = new mysqli($host, $user, $pw, $dbName);
    		
    		/* DB 연결 확인
    		if($conn){ echo "DB 연결 성공"."<br>"; }
    		else{ die( 'DB 연결 실패: ' . mysqli_error($conn) ); } */
    		
    		
    		/* select */
    		$sql = "select * from week";
    		$result = mysqli_query($conn, $sql);
    		
    	   
    		echo "<table border='1'>";
    		echo "<thead><th></th><th>조식</th><th>중식</th><th>석식</th><th>야식</th></thead><tbody>";
    		
    		
    		while($row = mysqli_fetch_array($result)){
    		    $i = 1;
    		    echo "<tr><th>".$row['date']."</th>";
    		    while($i <= 4){
    		        echo "<td>";
    		        
    		        $foodArr = explode(',', $row[$i]);
    		        foreach ($foodArr as $food){
    		            echo $food."<br>";
    		        }
    		        echo "</td>";
    		        $i++;
    		    }
    		   
    		    
    		    echo "</tr>";
    		}
    		
    		echo "</tbody></table>"
        ?>
	</body>
</html>