问题将PHP Mysql Jquery Bootstrap连接在一起并使用它们使用bootstrap模式并使用我自己的jquery代码

时间:2017-05-22 12:20:24

标签: javascript php jquery mysql twitter-bootstrap

我正在尝试编写网站代码。在收件箱页面中,我有一个通过PHP和MySQL接收并由CSS设置的消息列表。我要做的是当你点击每条消息时打开一个bootstrap模式。现在我正在尝试使用JQuery来使用ajax更改MySQLi并保存消息已被读取的事实,同时使用引导模式打开消息并让用户读取内容。但是当我尝试使用JQuery和ajax这样做时,它只是一无所获。这是页面的代码......

收件箱页面

    if ($row['readed'] == 0) {
        $action = '<a href="setasread.php?id='.$row["id"].'" data-toggle="modal" data-target="#myModal'.$row["id"].'" title="View" class="viewmarkajax"><i class="fa fa-eye" aria-hidden="true"></i></a> | <a href="setasread.php?id='.$row["id"].'" title="Mark as read"><i class="fa fa-envelope-o"></i></a>';
        $message_read_color = 'class="warning"';
    }
    else {
        $action = '<a href="" data-toggle="modal" data-target="#myModal' . $row["id"] . '" title="View"><i class="fa fa-eye" aria-hidden="true"></i></a>' .
                  ' | ' .
                  '<a href="setasunread.php?id=' . $row["id"] . '" title="Mark as unread"><i class="fa fa-envelope-open-o" aria-hidden="true"></i></a>';
        $message_read_color = 'class="success"';
    }

    echo '<tr ' . $message_read_color . '>\n';
    echo '    <td>' . $row["sender_name"] . '</td>\n';
    echo '    <td><a href="" data-toggle="modal" data-target="#myModal' . $row["id"] . '">' . $row["subject"] . '</a></td>\n';
    echo '    <td>' . $row["date"] . '</td>\n';
    echo '    <td>' . $rowtype . '</td>\n';
    echo '    <td>' . $action . '</td>\n';
    echo '</tr>\n\n';

    $message_content = $row["message"];

    echo '<div class="modal fade" id="myModal' . $row["id"] . '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">\n';
    echo '    <div class="modal-dialog" role="document">\n';
    echo '        <div class="modal-content">\n';
    echo '            <div class="modal-header">\n';
    echo '                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>\n\n';

    echo '                <h4 class="modal-title" id="myModalLabel">Subject: ' . $row["subject"] . '</h4>\n';
    echo '            </div>\n\n';

    echo '            <div class="modal-body">\n';
    echo '                From: ' . $row["sender_name"] . '<br>\n';
    echo '                Date Recieved: ' . $row["date"] . '<br><br>\n';
    echo '                ' . $message_content . '\n';
    echo '            </div>\n\n';

    echo '            <div class="modal-footer">\n';
    echo '                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>\n';
    echo '            </div>\n';
    echo '        </div>\n';
    echo '    </div>\n';
    echo '</div>\n';
}

setasread.php

require 'include/functions.php';
require 'include/usercnfg.php'; 

if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
    $messageid = $_GET['id'];

    $fquery = "SELECT `readed` FROM `messages` WHERE `id`=".$messageid;

    $fquery_run = mysqli_query( $conn, $fquery );

    $userdetails = mysqli_fetch_row( $fquery_run );

    if ( $userdetails[0] == 0 ) {
        $query = "UPDATE `messages` SET `readed`=1 WHERE `id`=" . $messageid;
        $query_run = mysqli_query( $conn, $query );
        $myredirection = "index.php?action=inbox";
        header( 'Location: ' . $myredirection );
    }
    else {
        echo "Already read.";
    }
}
else {
    echo "No id specified.";
}

jquery代码

$( document ).ready(function() {
    $('.viewmarkajax').click(function() {
        $.get($(this).attr('href'), function() {});
        return false;
    });
});

所以你可以看到我正在尝试使用bootstrap模式并定义我自己的JQuery。但显然我不能这样做。谁能告诉我一种方法呢?

0 个答案:

没有答案