asimryu

실시간검색

Jan 6th, 2015
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. [index.php]
  2. <!DOCTYPE HTML>
  3. <html lang="en-US">
  4. <head>
  5. <meta charset="UTF-8">
  6. <style>
  7. a {
  8. display:block;
  9. height: 50px;
  10. border-bottom:1px solid #ddd;
  11. line-height:50px;
  12. background-color:#eee;
  13. margin:0;
  14. }
  15. </style>
  16. <title></title>
  17. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/start/jquery-ui.css">
  18. <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  19. <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  20. </head>
  21. <body>
  22. <h1>게시판</h1>
  23. <form>
  24. 검색 <input type="text" name="sch" id="sch" onkeyup="saveSch();">
  25. </form>
  26. <div id="content"></div>
  27. <div id="more" onclick="list()">더보기</div>
  28. <div id="view" title="글보기" style="display:none;"></div>
  29. <script>
  30. var page = 0;
  31. var ls = window.localStorage;
  32. var sch = document.getElementById("sch");
  33. saveSch = function(){
  34. var txt = sch.value;
  35. ls.setItem("schText", txt);
  36. page = 0;
  37. $("#content").html("");
  38. list();
  39. }
  40. var schText = ls.getItem("schText");
  41. sch.value=schText;
  42.  
  43. function list(){
  44. page = page + 1;
  45. $.post("list.php",{page:page,sch:$("#sch").val()},function(result){$("#content").append(result);});
  46. }
  47. list();
  48.  
  49. function view(idx,title){
  50. $("#view").attr("title",title);
  51. $.get("view.php?idx=" + idx, function(data){
  52. $("#view").html(data);
  53. $("#view").dialog({
  54. width:500,
  55. height:500,
  56. modal: true,
  57. buttons:{
  58. "삭제":function(){
  59. var del = confirm("정말?");
  60. if(del){
  61. $.ajax({
  62. type: "POST",
  63. url:"action.php",
  64. data:{action: "delete", idx: idx},
  65. success: function(result){
  66. location.reload();
  67. }
  68. });
  69. }
  70. },
  71. "닫기":function(){
  72. $(this).dialog("close");
  73. }
  74. }
  75. });
  76. });
  77. }
  78.  
  79. </script>
  80. </body>
  81. </html>
  82.  
  83. [list.php]
  84. <?php
  85. require("dbcon.php");
  86. $limit = 5;
  87. $page = 1;
  88. $sch = "";
  89. $where = "";
  90. if(isset($_POST['page'])) $page=$_POST['page'];
  91. if(isset($_POST['sch'])) $sch=$_POST['sch'];
  92. $start = ($page-1) * 5;
  93. if($sch) $where = " where title like '%".$sch."%' or content like '%".$sch."%' ";
  94. $sql = "SELECT * FROM board ".$where." limit ".$start.",".$limit;
  95. $rs = $db->query($sql);
  96. while($row = $rs->fetch(PDO::FETCH_ASSOC)) {
  97. echo "<a href='javascript:view(".$row['idx'].",\"" . $row['title'] . "\")'>".$row['title']."</a>";
  98. }
Advertisement
Add Comment
Please, Sign In to add comment