이번 파트에서는 글 목록을 눌렀을 때, 해당 정보에 대한 상세 내용이 나오도록 코드를 짜 볼 것이다.

누른 목록과 맞는 정보가 나오도록 하기위해서는, id 값을 활용해서 가져오는 것이 편하다. (식별값)

그렇기 때문에, 내가 누른 정보의 id 를 먼저 가져와야한다.

var id = req.params.id;
if (id){
	var sql = "SELECT * FROM topic WHERE id=?"
	conn.query(sql, [id], function(error,topic,fields){
		if(error){
			// 개발자에게 에러가 있다는 것을 알려주는 코드
			console.log(error);
			//  컴퓨터에게 문제가 있음을 알려주는 코드
			res.status(500).send('Internal Server Error');
		}else{
			res.render('view', {
					topics:topics,
					topic:topic[0]
			});
		}
	});
}else{
	res.render('view', {
		topics:topics
	});
}

해당 코드를 작성하고 view.jade 파일을 수정한다.

상세보기와 관련된 태그를 수정한다.

(view.jade)

article
	if topic
		h2=topic.title
		=topic.description
		div= 'by '+topic.author
	else
		h2 Welcome
		| This is server side Javascript tutorial.

id 에 맞는 데이터가 담겨있는 topic 을 활용해서 상세보기 jade를 수정한다.


https://s3-us-west-2.amazonaws.com/secure.notion-static.com/474fff75-48df-4656-9289-7f10970ea89a/200522.mp4004.mp4