화면 결과
mysql 테이블
mysql 데이터
db 출력하기
<?php
$server_name = 'localhost:3307';
$user = 'root';
$password = '';
// $port = '3307';
$database = 'php';
$connect = mysqli_connect($server_name, $user, $password, $database);
mysqli_select_db($connect, $database) or die('db select failed');
$sql_query = 'select * from members order by age desc';
$result = mysqli_query($connect, $sql_query);
echo '<table border="1">';
echo '<tr>';
echo '<th>no</th>';
echo '<th>name</th>';
echo '<th>age</th>';
echo '<th>gender</th>';
echo '<th>registration date</th>';
echo '</tr>';
while($row = mysqli_fetch_array($result))
{
echo '<tr>';
echo '<td>'.$row['idx'].'</td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>'.$row['age'].'</td>';
echo '<td>'.$row['gender'].'</td>';
echo '<td>'.$row['regdate'].'</td>';
echo '</tr>';
}
echo '</table>';
mysqli_close($connect);
?>
반응형
'개발 > PHP' 카테고리의 다른 글
[php] form 전송 (GET, POST) (3) | 2024.03.17 |
---|---|
[xampp] apache vhost 환경설정 및 windows hosts 설정 (61) | 2023.03.20 |
[php] Warning: mysqli_connect(): (HY000/1045): Access denied for user 오류 (0) | 2023.01.20 |
댓글