如何使用按钮使限制变得更多?

时间:2016-05-22 05:32:28

标签: php html

我想要做的是使用一个按钮来加载更多消息。现在我已将其设置为限制40.如果用户点击加载更多按钮,则限制将变为50,60等等

我没有起诉如何实施,我看了很多例子仍然没有明确的想法如何做到

这是我的insert.php

<?php 

  include '../config.php';
  include'login.php';

  $username = $_SESSION['username'];
  $msg = $_REQUEST['msg'];

  date_default_timezone_set('Asia/Kuala_Lumpur');
  $today = date("Y-m-d H:i:s");

  $sql = mysqli_query($connection,"INSERT INTO logs(`username`, `msg`,`date`)VALUES('$username', '$msg','$today')");
  $sql1= "SELECT * FROM (
    SELECT * FROM logs ORDER BY id DESC LIMIT 40
        ) sub
        ORDER BY id ASC";

  mysqli_query ($connection,"delete from logs where date < DATE_SUB(NOW() , INTERVAL 1 MONTH)");

  $result1 = mysqli_query($connection,$sql1);

  while($extract = mysqli_fetch_array($result1)){
  $color = ($extract['username'] == $username) ? '  #F5F5F5' : '#DCDCDC';
   $position = ($extract['username'] == $username) ? 'right' : 'left';
  echo "
  <div class='left-wrap-message' style='background-color:$color; float:$position;'>
    <p style='text-align:$position; margin:0;'>". $extract['username']. " : </p>
        <p style='text-align:$position; margin:0; text-align:left;'>  "  . $extract['msg']. "</p></div>
        <div class='msg-dateandtime' style='text-align:$position;'> "  . $extract['date']. "</div>";
    }

?>

这是我的logs.php

<?php 

    include '../config.php';
    include'login.php';

    $username = $_SESSION['username'];

    $sql1= "SELECT * FROM (
        SELECT * FROM logs ORDER BY id DESC LIMIT 40
            ) sub
            ORDER BY id ASC ";

    $result1 = mysqli_query($connection,$sql1);

    while($extract = mysqli_fetch_array($result1)){
    $color = ($extract['username'] == $username) ? '    #F5F5F5' : '#DCDCDC';
     $position = ($extract['username'] == $username) ? 'right' : 'left';

     echo "
     <div class='left-wrap-message' style='background-color:$color; float:$position;'>
     <p style='text-align:$position; margin:0;'>". $extract['username']. "  : </p> 
     <p style='text-align:$position; margin:0; text-align:left;'>  " . $extract['msg']. "</p></div>
      <div class='msg-dateandtime' style='text-align:$position;'> "  . $extract['date']. "</div>";
    }

    ?>

这是我的HTML

<form name ="chatroom">

<button class="load_more" id="load_more_button">load More</button>
<div class="chatroom-upper-container" id="chatroom-upper-container">
    <div id="inner">
        Loading Message....<img src="../images/loading.gif"/>
    </div>
</div><div class="chatroom-lower-left-container">
    <textarea class="message-setting" id="area-message" placeholder="type text" name= "msg"></textarea>
</div><div class="chatroom-lower-right-container">
    <button type="button" class="btn sendmessage-btn" onclick= "submitChat()">Send</button>
</div>

希望任何人都可以帮助我

1 个答案:

答案 0 :(得分:1)

嗯,你可以尝试这个..首先在你的情况下带来记录的数量是40。如果有超过40条记录,则发送带有记录的标志..现在如果标志显示则显示加载更多按钮。 。并且在按钮的click事件上加载10个具有相同标志的记录。在div中存在10条记录,其中存在旧的40条记录。这将在标志关闭时标志打开,你隐藏加载更多按钮