Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [index.php]
- <!DOCTYPE HTML>
- <html lang="en-US">
- <head>
- <meta charset="UTF-8">
- <style>
- a {
- display:block;
- height: 50px;
- border-bottom:1px solid #ddd;
- line-height:50px;
- background-color:#eee;
- margin:0;
- }
- </style>
- <title></title>
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/start/jquery-ui.css">
- <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
- <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
- </head>
- <body>
- <h1>게시판</h1>
- <form>
- 검색 <input type="text" name="sch" id="sch" onkeyup="saveSch();">
- </form>
- <div id="content"></div>
- <div id="more" onclick="list()">더보기</div>
- <div id="view" title="글보기" style="display:none;"></div>
- <script>
- var page = 0;
- var ls = window.localStorage;
- var sch = document.getElementById("sch");
- saveSch = function(){
- var txt = sch.value;
- ls.setItem("schText", txt);
- page = 0;
- $("#content").html("");
- list();
- }
- var schText = ls.getItem("schText");
- sch.value=schText;
- function list(){
- page = page + 1;
- $.post("list.php",{page:page,sch:$("#sch").val()},function(result){$("#content").append(result);});
- }
- list();
- function view(idx,title){
- $("#view").attr("title",title);
- $.get("view.php?idx=" + idx, function(data){
- $("#view").html(data);
- $("#view").dialog({
- width:500,
- height:500,
- modal: true,
- buttons:{
- "삭제":function(){
- var del = confirm("정말?");
- if(del){
- $.ajax({
- type: "POST",
- url:"action.php",
- data:{action: "delete", idx: idx},
- success: function(result){
- location.reload();
- }
- });
- }
- },
- "닫기":function(){
- $(this).dialog("close");
- }
- }
- });
- });
- }
- </script>
- </body>
- </html>
- [list.php]
- <?php
- require("dbcon.php");
- $limit = 5;
- $page = 1;
- $sch = "";
- $where = "";
- if(isset($_POST['page'])) $page=$_POST['page'];
- if(isset($_POST['sch'])) $sch=$_POST['sch'];
- $start = ($page-1) * 5;
- if($sch) $where = " where title like '%".$sch."%' or content like '%".$sch."%' ";
- $sql = "SELECT * FROM board ".$where." limit ".$start.",".$limit;
- $rs = $db->query($sql);
- while($row = $rs->fetch(PDO::FETCH_ASSOC)) {
- echo "<a href='javascript:view(".$row['idx'].",\"" . $row['title'] . "\")'>".$row['title']."</a>";
- }
Advertisement
Add Comment
Please, Sign In to add comment