survey create table survey ans 1 int ans
survey 테이블 생성 및 초기화 create table survey( ans 1 int, ans 2 int, ans 3 int, ans 4 int ); insert into survey values(0, 0, 0, 0); survey. sql
예제 17 -1 설문조사 페이지 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 <html> <head> <title> 설문조사 </title> <link rel="stylesheet" href=". . /css/survey. css" type="text/css"> <meta charset="euc-kr"> <script> function update() { var vote; var length = document. survey_form. composer. length; for(var i=0; i<length; i++) { if(document. survey_form. composer[i]. checked==true) { vote=document. survey_form. composer[i]. value; break; } } survey. php
예제 17 -1 설문조사 페이지 survey. php 20 21 if(i==length) 22 { 23 alert("문항을 선택하세요!"); 24 return; 25 } 26 27 window. open("update. php? composer="+vote , "", 28 "left=200, top=200, width=160, height=250, status=no, scrollbars=no"); 29 } 30 31 function result() 32 { 33 window. open("result. php" , "", 34 "left=200, top=200, width=160, height=250, status=no, scrollbars=no"); 35 } 36 </script> 37 38 </head>
예제 17 -1 설문조사 페이지 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 survey. php <body> <form name=survey_form method=post > <table border=0 cellspacing=0 cellpdding=0 width='200' align='center'> <input type=hidden name=kkk value=100> <tr height=40> <td><img src=". . /img/bbs_poll. gif"></td> </tr> <tr height=1 bgcolor=#cccccc><td></tr> <tr height=7><td></tr> <tr><td><b> ♬ 가장 좋아하는 기타 작곡가는? </b></td></tr> <tr><td><input type=radio name='composer' value='ans 1' > 1. 타레가</td></tr> <tr height=5><td></tr> <tr><td><input type=radio name='composer' value='ans 2' > 2. 빌라로보스</td></tr> <tr height=5><td></tr> <tr><td><input type=radio name='composer' value='ans 3' > 3. 끌레양</td></tr> <tr height=5><td></tr> <tr><td><input type=radio name='composer' value='ans 4' > 4. 소르</td></tr> <tr height=7><td></tr>
예제 17 -1 설문조사 페이지 57 58 59 60 61 62 63 64 65 66 survey. php <tr height=1 bgcolor=#cccccc><td></tr> <tr height=7><td></tr> <td align=middle><img src=". . /img/b_vote. gif" border="0“ style='cursor: hand' onclick=update()></a> <img src=". . /img/b_result. gif" border="0" style='cursor: hand' onclick=result()></a></td></tr> </table> </form> </body> </html>
예제 17 -2 투표하기 01 <? 02 include ". . /lib/dbconn. php"; 03 04 $sql="update survey set $composer = $composer + 1"; 05 mysql_query($sql, $connect); 06 07 mysql_close(); 08 09 Header("location: result. php"); 10 ? > update. php
예제 17 -3 설문조사 결과 페이지 001 <? 002 include ". . /lib/dbconn. php"; 003 004 $sql="select * from survey"; 005 $result=mysql_query($sql, $connect); 006 $row=mysql_fetch_array($result); 007 008 $total=$row[ans 1] + $row[ans 2] + $row[ans 3] + $row[ans 4]; 009 010 $ans 1_percent=$row[ans 1]/$total * 100; 011 $ans 2_percent=$row[ans 2]/$total * 100; 012 $ans 3_percent=$row[ans 3]/$total * 100; 013 $ans 4_percent=$row[ans 4]/$total * 100; 014 015 $ans 1_percent=floor($ans 1_percent); 016 $ans 2_percent=floor($ans 2_percent); 017 $ans 3_percent=floor($ans 3_percent); 018 $ans 4_percent=floor($ans 4_percent); 019 ? > result. php
예제 17 -3 설문조사 결과 페이지 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 result. php <!-- 생략 --> <table width=250 height=250 border='0' cellspacing='0' cellpadding='0'> <tr> <td width=180 height=1 colspan=5 bgcolor=#ffffff></td> </tr> <td width=1 height=35 bgcolor='#ffffff'></td> <td width=9 bgcolor='#ffffff'></td> <td width=150 align=center bgcolor='#ffffff'><b> 총 투표수 : <? echo $total ? > 명 </b></td> <td width=9 bgcolor='#ffffff'></td> <td width=1 bgcolor='#ffffff'></td> </tr> <td height=29 bgcolor='#ffffff'></td> <td></td>
예제 17 -3 설문조사 결과 페이지 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 <td valign=middle><b>♬ 가장 좋아하는 기타 작곡가는? </b></td> <td bgcolor='#ffffff'></td> </tr> <td height=20 bgcolor='#ffffff'></td> <td> 타레가 (<b><? echo $ans 1_percent ? ></b> %) <font color=purple><b><? echo $row[ans 1] ? ></b></font> 명</td> <td></td> <td bgcolor='#ffffff'></td> </tr> <td height=3 bgcolor='#ffffff'></td> <td> <table width=100 border=0 height=3 cellspacing=0 cellpadding=0> <tr> result. php
예제 17 -3 설문조사 결과 페이지 061 062 063 064 065 066 067 068 069 070 071 072 073 <? $rest=100 - $ans 1_percent; echo(" <td width='$ans 1_percent%' bgcolor=purple></td> <td width='$rest%' bgcolor='#dddddd' height=5></td> )"; ? > </tr> </table> </td> <td></td> <td bgcolor='#ffffff'></td> </tr> <!-- 생략 --> result. php
예제 17 -3 설문조사 결과 페이지 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 result. php <tr> <td height=40 bgcolor='#ffffff'></td> <td align=center valign=middle> <input type='image' style='cursor: hand' src='. . /img/close. gif' border=0 onfocus=this. blur() onclick="window. close()"></td> <td bgcolor='#ffffff'></td> </tr> <td height=1 colspan=5 bgcolor=#ffffff></td> </tr> </table> </body> </html>
예제 17 -4 완성된 메인 화면 01 <? 02 session_start(); 03 ? > 04 <!DOCTYPE HTML PUBLIC "-//W 3 C//DTD HTML 4. 01 Transitional//EN" "http: //www. w 3. org/TR/html 4/loose. dtd"> 05 <html> 06 <head> 07 <meta http-equiv="Content-Type" content="text/html; charset=euc-kr"> 08 <link rel="stylesheet" type="text/css" href="css/common. css"> 09 </head> 10 11 <body> <!-- 생략 --> 24 <!-- 최근 글 불러오기 시작 --> 25 <? include ". /lib/func. php"; ? > 26 27 <div id="latest"> 28 <div id="latest 1"> index. php
예제 17 -4 완성된 메인 화면 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 <div id="title_latest 1"><img src=". /img/title_latest 1. gif"></div> <div class="latest_box"> <? latest_article("greet", 10, 30); ? > </div> <div id="latest 2"> <div id="title_latest 2"><img src=". /img/title_latest 2. gif"></div> <div class="latest_box"> <? latest_article("concert", 10, 30); ? > </div> <!-- 최근 글 불러오기 끝 --> </div> </body> </html> index. php
예제 17 -5 최근 글 불러오기 01 <? 02 function latest_article($table, $loop, $char_limit) 03 { 04 include "dbconn. php"; 05 06 $sql="select * from $table order by num desc limit $loop"; 07 $result=mysql_query($sql, $connect); 08 09 while($row=mysql_fetch_array($result)) 10 { 11 $num=$row[num]; 12 $len_subject=strlen($row[subject]); 13 $subject=$row[subject]; 14 15 if($len_subject>$char_limit) 16 { 17 $subject=mb_substr($row[subject], 0, $char_limit, 'euc-kr'); func. php
예제 17 -5 최근 글 불러오기 18 19 20 21 22 23 24 $subject=$subject. ". . . "; } $regist_day=substr($row[regist_day], 0, 10); echo(" <div class='col 1'> <a href='. /$table/view. php? table=$table&num=$num'>$subject</a> </div><div class='col 2'>$regist_day</div> <div class='clear'></div> "); 25 26 27 } 28 mysql_close(); 29 } 30 ? > func. php
- Slides: 26