웹마스터 팁
페이지에 명언,좋은글,책속의 한줄 랜덤으로 뿌리기
2014.12.02 16:11
한글 다 깨지니
페이지 상단에 밑에 태그 넣고
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
파일 저장은 UTF-8 로 반드시 해야 합니다.(메모장 또는 editplus 추천 다른 에디터는 제대로 적용안되더군요)
1.파일형식으로 코딩
밑의 코드페이지와 위의 첨부파일을 같은 폴더에 둡니다.
<?
$mentFile = "book.txt";
$fp = fopen($mentFile, "r");
while(!feof($fp)) $ment[] = fgets($fp, 1024);
//### $ment 배열에서 랜덤키 생성
$key = array_rand($ment);
### 랜덤 생성된 명언 출력
echo $text_this=$ment[$key];
?>
2.my_sql 연동방식
1.테이블 생성
CREATE TABLE IF NOT EXISTS `books` (
`no` int(11) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
PRIMARY KEY (`no`),
KEY `no` (`no`)
)
2.mysql 에 위에 첨부된 book.txt 집어 넣습니다.
phpmyadmin 에서 import 탭에서
CSV using LOAD DATA book.txt 파일 첨부
CSV using LOAD DATA 체크
필드 구분자 -> \t
필드 구분자-> content
로 하는것 유의
방법은 서기님 강좌 참고http://vod.singsinghe.co.kr/movie/php/48/php_48.html
3.코딩
<?
$conn=mysql_connect("","","");
mysql_select_db("");
<embed autostart="false" invokeurls="false" width="100%" height="100%" wmode="transparent" id="syeatistorycom49563" src="http://s1.daumcdn.net/cfs.tistory/v/0/blog/plugins/CallBack/callback.swf?destDocId=callbacknestsyeatistorycom49563&id=49&callbackId=syeatistorycom49563&host=http://syea.tistory.com&float=left&" allowscriptaccess="never" menu="false" type="application/x-shockwave-flash" allownetworking="internal" enablehtmlaccess="false" allowhtmlpopupwindow="false" />
$random = rand(1,283); //no 의 처음과 끝사이에 랜덤하게 1개 $random 변수에 지정 (db 넘버 반드시 확인 )
$query="select * from books where no='$random'"; // 랜덤 생성된 1개 no 필드에서 가져오기
$result=mysql_query($query,$conn);
$data=mysql_fetch_array($result);
$text_this=$data[1];
echo $text_this;
?>
하면 됩니다..
3.
JQuery 로
뿌리기
위와 같이 바로 해도 되고..같은 폴더에 코딩 한거 두고 뿌리기 원하는 페이지에
JQuery 로 가져 와도 됩니다.
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#div1").load("books.php");
});
</script>
</head>
<body>
<div id="div1"></div><div id="div"></div>
</body>
4.이쁘게 둥근 테두리로 만들기
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
td{
font-size:12px;
}
</style>
<table cellpadding=0 cellspacing=0 border=0 width=300 >
<tr height=1>
<td rowspan=4 width=1></td>
<td rowspan=3 width=1></td>
<td rowspan=2 width=1></td>
<td width=2></td>
<td bgcolor=#3DB7CC></td>
<td width=2></td>
<td rowspan=2 width=1></td>
<td rowspan=3 width=1></td>
<td rowspan=4 width=1></td>
</tr>
<tr height=1>
<td bgcolor=#3DB7CC></td>
<td bgcolor=#D4F4FA></td>
<td bgcolor=#3DB7CC></td>
</tr>
<tr height=1>
<td bgcolor=#3DB7CC></td>
<td colspan=3 bgcolor=#D4F4FA></td>
<td bgcolor=#3DB7CC></td>
</tr>
<tr height=2>
<td bgcolor=#3DB7CC></td>
<td colspan=5 bgcolor=#D4F4FA></td>
<td bgcolor=#3DB7CC></td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 border=0 width=300 >
<tr >
<td width=1 bgcolor=#3DB7CC></td>
<td valign=top bgcolor=#D4F4FA>
<table cellpadding=0 cellspacing=0 border=0 width=100%>
<tr height=0><td></td>
<td></td>
<td></td>
</tr>
<tr>
<td width=0></td>
<td align="center">
<?
$conn=mysql_connect("localhost","","");
mysql_select_db("");
$random = rand(1,283);
$query="select * from books where no='$random'";
$result=mysql_query($query,$conn);
$data=mysql_fetch_array($result);
$text_this=nl2br($data[1]);
echo $text_this;
?>
</td>
<td width=0></td>
</tr>
<tr height=0>
<td></td>
<td bgcolor=#D4F4FA></td>
<td></td>
</tr>
</table>
</td>
<td width=1 bgcolor=#3DB7CC></td>
</tr>
</table>
<table cellpadding=0 cellspacing=0 border=0 width=300 >
<tr height=2>
<td rowspan=4 width=1></td>
<td width=1 bgcolor=#3DB7CC></td>
<td width=1 bgcolor=#D4F4FA></td>
<td width=2 bgcolor=#D4F4FA></td>
<td bgcolor=#D4F4FA></td>
<td width=2 bgcolor=#D4F4FA></td>
<td width=1 bgcolor=#D4F4FA></td>
<td width=1 bgcolor=#3DB7CC></td>
<td rowspan=4 width=1></td>
</tr>
<tr height=1>
<td rowspan=3></td>
<td bgcolor=#3DB7CC></td>
<td colspan=3 bgcolor=#D4F4FA></td>
<td bgcolor=#3DB7CC></td>
<td rowspan=3></td>
</tr>
<tr height=1>
<td rowspan=2></td>
<td bgcolor=#3DB7CC></td>
<td bgcolor=#D4F4FA></td>
<td bgcolor=#3DB7CC></td>
<td rowspan=2></td>
</tr>
<tr height=1>
<td></td>
<td bgcolor=#3DB7CC></td>
<td></td>
</tr>
</table>
제목 | 글쓴이 | 날짜 |
---|---|---|
정식버전 후 갤러리 스킨 사용시 이미지 정렬 안되시는 분들~ | 다케루 | 2008.02.29 |
홈페이지에 국경일이면 태극기 다는법이에요~ ^^ [11] [1] | jaehee_91 | 2008.03.01 |
게시판 확장 변수에 그림 입력받기 [7] | 대암지기 | 2008.03.04 |
게시판 확장변수에 라디오버튼 추가해서 사용하기 [6] | 똑디 | 2008.03.04 |
utf-8 저장시 레이아웃 윗부분 빈공간이 생기는 문제 (BOM)처리 [8] | 주금보 | 2008.03.04 |
회원 기본정보 공개여부 및 정보변경 옵션으로 처리하기(Member Moudle) [18] | 대암지기 | 2008.03.04 |
확장변수 쉽게 출력하기 [7] | lightnsalt | 2008.03.04 |
리스트를 작성날짜(regdate)로 정렬하기 [7] | JAMSUN2 | 2008.03.05 |
우분투에서 rewrite 모드 사용하기 [2] | 용꿍 | 2008.03.06 |
기초적인 배경등록시 게시판투명되는것 고치는법[초보만] [3] | 이정제421 | 2008.03.07 |
제로보드 XE에 연동 가능 채팅, 100% 플래시, 1:1 채팅 지원, 필요하면 음성/화상 채팅 지원 [2] | digirave | 2008.03.09 |
애드온에서 그룹 별로 실행여부 설정 [1] | imsoo.net | 2008.03.09 |
[수정 했습니다.]본문 입력없이 확장 변수로만 글작성 작성하기(그림삽입포함) [13] | 대암지기 | 2008.03.09 |
글작성및수정, 코멘트작성및 수정을 하면 미리 입력한 메일주소로 메일발송 [18] | 채연파파 | 2008.03.12 |
동창회 사이트용 프로필 이미지 두개 출력하기 [1] | 지연아빠 | 2008.03.12 |
zbXE에 퍼머링크 달기 [3] | 라르게덴 | 2008.03.13 |
관리 화면의 회원 목록에서 소속 그룹 출력하기 [6] | 띵야 | 2008.03.14 |
큰 파일의 썸네일이 안생기는 경우 해결방법(수정) [12] | 얼터 | 2008.03.15 |
팝업창 띄우기 [16] | 레망 | 2008.03.16 |
큰 파일의 썸네일이 안생길때 해결방법-추가 [7] | HIKARU | 2008.03.18 |
감사합니다. 수고하셨습니다~