Web Programming >> PHP Programming
|
[목차] |
제21장 온라인 서점 쇼핑몰 만들기
6. 사용자(구매자) - 제품 목록 보기 디렉토리 및 파일 구조는 다음과 같다. / -- shop/ -- admin/ --- product/ --(제품관리) | | | | | +-- list.html | | +-- postform.html.html | | +-- post.html | | +-- viewbody.html | | +-- modifyform.html | | +-- modify.html | | +-- deleteform.html | | +-- delete.html | | | +- order/ (주문관리) | | | | | +-- index.html | | +-- viewuser.html | | +-- modify.html | | +-- delete.html | | | +- admin.html (관리자 인증에 필요한 파일) | +- index.html (아이디와 암호를 입력하는 폼) | +- login_process.html (로그인 처리프로그램) | +- home.html (관리자 화면) | +- menu.html (메뉴) | +- welcome.html (환영 메시지) | +- logout.html (종료 프로그램) | +-- user_function.html (사용자 정의 함수들) +-- dbconn.html (DB connect에 필요한 파일) | +-- index.html (온라인 서점 처음화면) +-- top.html +-- menu.html (메뉴) +-- welcome.html +-- list.html (제품 목록 보기) +-- viewproduct.html (제품 세부내역 보기)
1. 메인 화면 구성 파일명 : index.html
<html> <head><title> LeeLAB's 온라인 서점</title></head> <frameset border=1 rows="70,*"> <frame scrolling=no noresize src="top.html" name=bookshop-main-top> <frameset border=1 cols="135,*"> <frame scrolling=no noresize src="menu.html" name=bookshop-main-menu> <frame scrolling=auto src="welcome.html" name='bookshop-main-detail'> </frameset> </frameset> </html>
파일명 : menu.html <HTML> <HEAD> <TITLE> 메뉴 </TITLE> </HEAD> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; font-size: 10pt; } a:hover { text-decoration : underline; font-size: 10pt; color : red; } //--> </style>
<BODY BGCOLOR="#EEEEEE"> <br> <LI> <A HREF="./" target="_top">홈으로</A><p> <LI> <A HREF="list.html?part=컴퓨터" target="bookshop-main-detail">컴퓨터</A> <LI> <A HREF="list.html?part=소설" target="bookshop-main-detail">소설</A><p>
<LI> <A HREF="list_bag.html" target="bookshop-main-detail">장바구니보기</A> </BODY> </HTML>
파일명 : welcome.html
<HTML> <HEAD> <TITLE> 환영합니다. </TITLE> </HEAD> <BODY BGCOLOR="#EEEEEE"> <br> <center> <h1>방문을 환영합니다. </h1> </center> </BODY> </HTML>
파일명 : top.html <HTML> <HEAD> <TITLE> 환영합니다. </TITLE> </HEAD> <BODY BGCOLOR="#BBBBBB"> <br> <h1>LeeLAB's 온라인 서점 </h1> </BODY> </HTML>
2. 제품 목록 보기
파일명 : list.html <? session_start();
include "./user_function.html"; include "./dbconn.html";
$imgdir = "./product_files";
if(!$user_uid) {
$result = mysql_query("SELECT max(uid)+1 FROM sold"); if (!$result) { error("QUERY_ERROR"); exit; } $new_uid = (int)mysql_result($result,0,0);
$query = "INSERT INTO sold (uid) VALUES ($new_uid)"; $result = mysql_query($query); if (!$result) { error("QUERY_ERROR"); exit; }
session_register("user_uid"); $user_uid = $new_uid; } ?> <html> <head> <title>온라인 쇼핑몰</title> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; } a:hover { text-decoration : underline; color : red; } TABLE, TD, TR, TH { font-size : 10pt; } //--> </style> <script language="javascript"> <!-- function newWindow(ref) { var window_left = (screen.width-900)/2; var window_top = (screen.height-500)/2; window.open(ref,"profilewindow",'width=900,height=500,status=no,scrollbars=yes,top=' + window_top + ',left=' + window_left + ''); } //--> </script>
<script language="javascript"> <!-- var viewproduct = null; function view_product_Window( linkpage ) { viewproduct = window.open('','view_product','width=450,height=450,scrollbars=auto,resizable=no'); if (viewproduct != null) { if (viewproduct.opener == null) { viewproduct.opener = self; } viewproduct.location.href = linkpage; } } //--> </script> </head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red"> <p> <table border="0" cellpadding="0" width="800" align=left> <tr> <td align=center> <? $query1 = "SELECT count(uid) FROM product WHERE part='$part' "; $result1 = mysql_query($query1); if (!$result1) { error("QUERY_ERROR"); exit; } $total_record1 = mysql_result($result1,0,0);
echo("<font size=3><b>$part</b></font>"); ?>
<table border="0" width="600" align="center" cellspacing="0" cellpadding="0"> <tr><td colspan=3><hr size=1></td></tr>
<?
########## 현재페이지의 범위내에 출력할 결과레코드세트를 얻는다. ########## if(!eregi("[^[:space:]]+",$key)) { $query1 = "SELECT uid,name,author,price,userfile,info FROM product WHERE part='$part' ORDER BY name"; } else { $query1 = "SELECT uid,name,author,price,userfile,info FROM product WHERE part='$part' AND $keyfield LIKE '%$key%' ORDER BY name"; } $result1 = mysql_query($query1); if (!$result1) { error("QUERY_ERROR"); exit; }
########## 게시물의 가상번호(게시물의 개수에 따른 일련번호) ##########
for($i = 0; $i < $total_record1; $i++) { $my_p_uid = mysql_result($result1,$i,0); $my_p_name = mysql_result($result1,$i,1); $my_p_author = mysql_result($result1,$i,2); $my_p_price = mysql_result($result1,$i,3); $my_p_imgname = mysql_result($result1,$i,4); $my_p_info = mysql_result($result1,$i,5); ?> <tr><td width="100" rowspan=4 align=center> <?if($my_p_imgname == ""){ echo("<font color=red>그림없음"); }else {?> <img src=<?echo("$imgdir/$my_p_imgname");?> border=0> <?}?> </td><td width=90>도서명</td> <td height="25" align=left> <a href="javascript:view_product_Window('viewproduct.html?number=<?echo("$my_p_uid");?>')"><?echo("$my_p_name");?></a> </td></tr> <tr><td height="25">지은이</td> <td height="25" align=left><?echo("$my_p_author");?></td> </tr> <tr><td height="100%">내용</td> <td valign="top" height="25" align=left> <?echo("$my_p_info");?></td> </tr> <tr><td height="25">가격</td> <td height="25" align=left><?echo("$my_p_price");?> <a href="save_bag.html?part=<?echo("$part");?>&number=<?echo("$my_p_uid");?>">담기</a> </td></tr> <tr><td colspan=3><hr size=1></td></tr> <? } echo("</table>"); ?> <br><br> </td></tr> </table> </body> </html>
파일명 : viewproduct.html <? include "./user_function.html"; include "./dbconn.html";
?>
<html>
<head> <title>제품세부내역 조회</title> </head> <style type="text/css"> <!-- a:link,a:visited,a:active { text-decoration : none; font-size: 10pt; } a:hover { text-decoration : underline; font-size: 10pt; color : red; } //--> </style> <body bgColor="#FFFFFF"> <table width="400" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td align=center height=30><b><font size=4>제품 세부내역 조회</font></b></td> </tr> </table> <?
########## 파일이 저장될 자료실의 디렉토리를 설정한다. ########## $savedir = "./product_files";
########## 선택한 게시물의 입력값을 뽑아낸다. ########## $query = "SELECT uid,name,part,author,price,date,info,remain,userfile FROM product WHERE uid = $number"; $result = mysql_query($query); if(!$result) { error("QUERY_ERROR"); exit; } $row1 = mysql_fetch_row($result);
$my_uid = $row1[0]; $my_name = $row1[1]; $my_part = $row1[2]; $my_author = $row1[3]; $my_price = $row1[4]; $my_date = $row1[5]; $my_info = $row1[6]; $my_remain = $row1[7]; $my_filename = $row1[8];
########## addslashes() 함수로 escape된 제목과 본문의 문자열을 원상복귀시킨다. $my_info = stripslashes($my_info);
########## 원칙상 제목에는 HTML 태그를 허용하지 않는다. ########## $my_info = htmlspecialchars($my_info);
########## 검색어가 있을 경우 검색어를 red color처리하여 출력한다. ########## if(!strcmp($keyfield,"info") && $key) { $my_info = eregi_replace("($key)", "<font color=red>\\1</font>", $my_info); } if(!strcmp($keyfield,"name") && $key) { $my_name = eregi_replace("($key)","<font color=red>\\1</font>",$my_name); } if(!strcmp($keyfield,"author") && $key) { $my_author = eregi_replace("($key)","<font color=red>\\1</font>",$my_author); }
########## 본문의 문자열을 개행처리한다. ########## $my_info = nl2br($my_info);
?> <table width=400 border=0 cellpadding=1 cellspacing="0" align="center"> <tr> <td bgColor="#000000"> <table width=400 border=0 cellpadding=5 cellspacing="1" align="center"> <tr> <td colspan="2" align="center" bgColor="#FFFFFF"><font color="#000000" size="2"><b><?echo("$my_name")?></b></font></td> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">글 쓴 이</font></td> <? echo("<td width=\"75%\" bgColor=\"#EEEEEE\"><font size=2>$my_author</font></td>"); ?> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">가격</font></td> <? echo("<td width=\"75%\" bgColor=\"#EEEEEE\"><font size=2>$my_price</font></td>"); ?> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">출 판 일</font></td> <td width="75%" bgColor="#EEEEEE"><font size="2"><?echo("$my_date")?></font></td> </tr> <tr> <td align="center" bgColor="#BBBBBB"><font color="#000000" size="2">소 개</font></font></td> <td bgColor="#EEEEEE"><font size="2"><?echo("$my_info")?></font></td> </tr> <tr> <td width="25%" align="center" bgColor="#BBBBBB"><font color="#000000" size="2">그림</font></td> <td width="75%" bgColor="#EEEEEE"><font size="2"> <?if($my_filename !="") echo("<img src=\"$savedir/$my_filename\" border=\"0\" hspace=\"2\"> ")?></font></td> </tr> </table> </td></tr> </table> </body> </html>
|
[목차] |