如何添加阅读更多链接以在模态框

时间:2018-03-21 10:52:59

标签: php mysql

在我审核了可能的重复内容之后,我刚刚编辑了这个问题limit text length in php and provide 'Read more' link 但它仍然没有指向我想要的东西所以我决定放下我的桌子的图像以便更好地理解。 html result table 在此表中是从mysql数据库显示的帖子。现在我不希望帖子完全显示,直到我点击一个。只有这样才能显示完整的帖子“IN A MODAL BOX POPUP”。

以下是我的文件:

home.php

<?php
include 'config/server.php';

    // if session is not set this will redirect to login page
    if( !isset($_SESSION['user']) ) {
        header("Location: index.php");
        exit;
    }
    // select loggedin users detail
  $res=mysqli_query($dbconn, "SELECT * FROM users WHERE id=".$_SESSION['user']);
    $userRow=mysqli_fetch_array($res);

  // fetch the records to be updated
  if (isset($_GET['update'])) {
    $id = $_GET['update'];
    $edit_state = true;
    $rec = mysqli_query($dbconn, "SELECT * FROM diary_table WHERE id=$id");
    $records = mysqli_fetch_array($rec);
    $note = $records['note'];
    $id = $records['id'];
  }

?>

                <div class="table-responsive">  
                <table class="table table-bordered">  
    <thead>
      <tr>
        <th>Note</th>
        <th>created</th>
        <th>Updated</th>
        <th colspan="2">Action</th>
      </tr>
    </thead>
    <tbody>
      <?php while ($row = mysqli_fetch_array($results)) { ?>
      <tr>
        <td><?php echo $row['note']; ?><a href="#view" data-toggle="modal" class="btn btn-info btn-xs view_data">View</a></td>
        <td><?php echo $row['created_at']; ?></td>
        <td><?php echo $row['updated_at']; ?></td>
          <td>
          <a style="text-decoration: none; padding: 2px 5px; background: #2E8B57; color: #FFFFFF;  border-radius: 3px;" href="home.php?update=<?php echo $row['id']; ?>">Update</a>
          </td>
        <td>
          <a style="text-decoration: none; padding: 2px 5px; color: #FFFFFF; border-radius: 3px; background: #800000;" href="config/server.php?del=<?php echo $row['id']; ?>">Delete</a>
        </td>
      </tr>
    <?php } ?>
    </tbody>
  </table>
      </div>
  </div>

<!-- Modal -->
<div class="modal" id="view" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <form class="form-horizontal">
        <div class="modal-header">
          <h4>Full Note</h4>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <div class="col-lg-10">
<textarea disabled>
              <?php echo $id; ?>
              <?php echo $note; ?>
  `</textarea>`          </div>
          </div>
          <div class="modal-footer">
            <a href="#" class="btn btn-default" data-dismiss="modal">Close it</a>
            </div>
        </div>
      </form>
    </div>
  </div>
</div>

和server.php

<?php
    session_start();
    // initialize variables
        // $note = "";
        // $id = 0;
        // $edit_state = false;

    error_reporting(E_ALL);
    // connect to database
    require_once 'database.php';

        if( !isset($_SESSION['user']) ) {
        header("Location: index.php");
        exit;
    }

    // if save button is clicked
    if (isset($_POST['save'])) {
        $note = addslashes($_POST['note']);
        $created_at = date("Y-m-d H:i:s");
        $user_id = trim($_SESSION['user']);

    // basic post validation
    if (empty($note)) {
        $error = true;
        $noteError = "Field cannot be empty.";
    }else {
        // insert records if no error
        echo 
        $query = "INSERT INTO diary_table (note, user_id, created_at) VALUES ('$note', ' ".$user_id." ' , '$created_at'";
        mysqli_query($dbconn, $query);
        header('location: ../home.php'); // redirect to home page after inserting
    }
}
    // update records
    if (isset($_POST['update'])) {
        $note = $_POST['note'];
        $id = $_POST['id'];
        $_SESSION['msg'] = "Note updated";
        mysqli_query($dbconn, "UPDATE diary_table SET note='$note', updated_at=NOW() WHERE id=$id");
        header('location: ../home.php');
    }

    // delete records
    if (isset($_GET['del'])) {
        $id = $_GET['del'];
        mysqli_query($dbconn, "DELETE FROM diary_table WHERE id=$id");
        $_SESSION['msg'] = "Shipment deleted";
        header('location: ../home.php');
    }
    // retrieve records
    $results = mysqli_query($dbconn, "SELECT * FROM diary_table WHERE user_id=".$_SESSION['user']);
?>

0 个答案:

没有答案