본문 바로가기

분류 전체보기136

[Nodejs-mysql] 테이블값 삭제하기 [생활코딩] 저자 삭제 기능 구현 테이블값 삭제하기 lib/template.js uthorTable:function(authors){ var tag = ''; var i = 0; while(i < authors.length){ tag += ` ${authors[i].name} ${authors[i].profile} update `; // delete는 링크가 아닌 form으로 만들어야 함 // delete는 클릭 시 /author/delete_process 이동하고 id값으로 authors[i].id 전달 i++; }; tag += ''; return tag; } lib/author.js exports.delete_process = function(request, response){ var body = .. 2020. 8. 7.
[Nodejs-mysql] 테이블값 업데이트 하기 [생화코딩] 저자 수정 기능 구현 lib/template.js authorTable:function(authors){ var tag = ''; var i = 0; while(i < authors.length){ tag += ` ${authors[i].name} ${authors[i].profile} update delete `; i++; }; // update에 a태그 붙이고 이동 링크는 author/update?id=author의 id값 tag += ''; return tag; } lib/author.js var db = require('./db'); var template = require('./template.js'); var qs = require('querystring'); var url = r.. 2020. 8. 7.
[Nodejs-mysql] 폼 만들고 모듈 분리하기 [생활코딩] 저자 생성 기능 구현 main.js else if(pathname === '/author/create_process'){ author.create_process(request,response); } lib/author.js var db = require('./db'); var template = require('./template.js'); var qs = require('querystring'); exports.home = function(request, response){ db.query('SELECT*FROM topic', function(error, topics){ db.query('SELECT*FROM author', function(error2, authors){ var title.. 2020. 8. 7.
[Nodejs-mysql] 테이블 만들고 모듈 분리하기 [생활코딩] 저자 목록 보기 기능 구현 main.js var author = require('./lib/author'); else if(pathname === '/author'){ author.home(request,response); } lib/author.js var db = require('./db'); var template = require('./template.js'); exports.home = function(request, response){ db.query('SELECT*FROM topic', function(error, topics){ db.query('SELECT*FROM author', function(error2, authors){ // author데이터 불러와 authors에 .. 2020. 8. 7.
[Nodejs-mysql] DB 관련 코드 모듈로 분리하기 [생활코딩] Node.js 코드의 정리정돈 (topic) home 분리하기 main.js var topic = require('./lib/topic'); // topic모듈 불러오기 if(pathname === '/'){ if(queryData.id === undefined){ topic.home(request,response); // topic모듈의 home 사용하기 // 인자로 request,response 전달 } else { ... } } lib/topic.js var db = require('./db'); var template = require('./template.js'); exports.home = function(request,response){ // 한 모듈에서 여러개 내보낼 때는 ex.. 2020. 8. 7.
[Nodejs-mysql] Select값 수정하기 [생활코딩] MySQL join을 이용해서 글수정 구현 수정페이지에 Select 넣고 선택되었던 option 출력하기 main.js if(pathname === '/update'){ db.query('SELECT*FROM topic', function(error, topics){ if(error){ throw error; } db.query('SELECT*FROM topic WHERE id=?', [queryData.id], function(error2, topic){ if(error2){ throw error2; } db.query('SELECT*FROM author', function(error3, authors){ // author값 받아서 authors에 담기 var list = template... 2020. 8. 7.
반응형