반응형
name 테이블과 count 테이블을 join하여 표시하기!
select * from nameTBL a inner join countTBL b on a.id=b.id;
결과>
특정 column만 출력하기
select id,name,count from nameTBL a inner join countTBL b on a.id=b.id;
결과>
: id column이 nameTBL과 countTBL에도 존재하기때문에 어느 테이블의 id인지 명시해줘야한다!
select a.id,name,count from nameTBL a inner join countTBL b on a.id=b.id;
결과>
간략화한 코드
<?php
try{
$conn=new PDO("mysql:host=localhost;dbname=testdb","root","111111");
$stmt=$conn->prepare("select a.id,name,count from nameTBL AS a, countTBL AS b where a.id=b.id");
$stmt->execute();
while ($row=$stmt->fetch(PDO::FETCH_ASSOC)){
echo $row['id'] . " : " . $row['name'] . " : " . $row['count'];
}
}catch (PDOException $e){
echo $e->getMessage();
}
?>
반응형
'WEB > PHP' 카테고리의 다른 글
[PHP] 문자열 HTML화, htmlspecialchars() (0) | 2020.09.22 |
---|---|
[PHP] isset() , empty() (0) | 2020.09.11 |
[PHP] MySQL_SELECT : PDO fetch(), fetchAll(); (0) | 2020.09.08 |
[PHP] MySQL_SELECT : mysqli_fetch_array(); (0) | 2020.09.08 |
[PHP] MySQL_SELECT : mysqli_fetch_assoc(); (0) | 2020.09.08 |