如何使我的javascript函数在foreach循环中的其他id中工作

时间:2018-01-11 01:36:28

标签: javascript php html mysql

大家好我试图建立一个论坛,我可以查看和评论其他状态,但我的脚本只能在其他状态ID的第一个状态ID中工作

这是我的feedbox.php

<?php 
$selectAll = $con->prepare("SELECT * FROM tblstatus");
$selectAll->execute();
$count = $selectAll->rowCount();
if($count > 0){
    $result = $selectAll->fetchAll();
    foreach ($result as $status) {
        $statusId = $status['status_id'];
        $statusTitle = $status['status_title'];
        $statusContent = $status['status_content'];
        $statusCategory = $status['status_category'];
        $statusDatePosted = $status['status_dateposted'];
        $statusTimePosted = $status['status_timeposted'];
        $statusUser = $status['status_user'];
在foreach循环中我有这些代码来循环我的html

<div class="col-lg-12">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <?=$statusUser ?><label class="label label-success pull-right"><?=$statusCategory ?></label>
            <hr>
            <strong><?=$statusTitle ?></strong>
        </div>
        <div class="panel-body">
            <i class="fa fa-quote-left fa-3x fa-pull-left fa-border"></i>
            <input type="text" name="statusId" id="statusId" value="<?=$statusId ?>">
            <?=$statusContent ?>
        </div> 
        <div class="panel-footer">
            <?php 
            $time = strtotime($statusTimePosted); 
            echo date('h:i A', $time); 
            ?> 
            - 
            <?php
            $date = strtotime($statusDatePosted);
            echo date('F j,Y', $date);
            ?>        
            <i class="badge badge-success">Comments</i>
            <button class="btn btn-success btn-xs pull-right" id="btnView" name="btnView">View</button>
            <br>
        </div>
    </div>
</div>


    }

}

这是我的剧本

    $('#btnView').on('click', function(e){
        e.preventDefault();
        var status_id = $("#statusId").val();
        alert(status_id);
        $(location).attr('href','statuswall?statusid='+status_id);
    });

在状态墙页面中,我已经回显了statusid。

0 个答案:

没有答案