0

我有个问题。我想在页面中显示每个“主题”(标题),而不仅仅是像现在这样的第一个。当我添加一条新消息时,索引只显示第一条消息,只有当我单击“打开”按钮时,我才能看到所有消息。

有什么建议吗?

非常感谢。

这是解码代码:

<?php
require_once("config.php");
if (isset($_SESSION['username']) === FALSE){
    header('location:login.php');
    exit();
}
$where = "";
$searchCriteria = "";
if (isset($_GET['search']) && $_GET['search'] != '') {
    $searchCriteria = mysql_real_escape_string($_GET['search']);
    $where = " WHERE subject LIKE '%" . $searchCriteria . "%'";
    $where .= " OR message like '%" . $searchCriteria . "%'";
}
$sql = "SELECT * FROM notes " . $where . " LIMIT 30";
$result = mysql_query($sql);
?>
<!DOCTYPE html>
html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

</head>
<body>
<a href="logout.php">Logout</a><br/><br/>

<div id="wrapper">

    <div id="add-message">
        <a href="add.php"><img src="images/add.png" title="Add"> Add a New   Message</a>
    </div>
    <br>
    <?php
    while ($row = mysql_fetch_assoc($result)) {
    ?>
    <?php echo $row['subject']; ?>
    <input type="button" id="opener" value="Open"/>
        <div id="playbox"> 
            <table id="general">
                <thead>
                    <tr>
                        <th class="general-header"></th>
                        <th class="general-subject">Subject</th>
                        <th class="general-message">Message</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="4" class="general-foot"><input type="button" id="closer" value="Close"/></td>
                    </tr>
                </tfoot>
                <tbody>
                    <tr>
                        <td>
                            <a href="edit.php?id=<?php echo $row['id']; ?>"><img src="images/edit.png" title="Edit"> Edit</a>
                                                     &nbsp;|&nbsp; 
                            <a href="delete.php?id=<?php echo $row['id']; ?>"><img src="images/delete.png" title="Delete"> Delete</a>
                        </td>
                        <td class="subject"><?php echo $row['subject']; ?></td>
                        <td><?php if ($row['filename']!=''){?>
                            <img align="right" width="300px" src="<?php echo $row['filename']; ?>" />
                            <?php } ?>
                            <?php echo $row['message']; ?>
                        </td>
                    </tr>
                </tbody>
            <?php
            }
            ?>
            </table>
        </div>
</div>
</body>
</html>

<script>
$(document).ready(function(){
    $("#playbox").hide();

    $("#opener").click(function(){
        $("#playbox").slideDown(600); 
    });

    $("#closer").click(function(){
        $("#playbox").slideUp(600); 
    });
});
</script>
4

2 回答 2

0

我认为你应该使用mysql_num_rows它并且你不需要你创建很多open,只需添加一次就像你一样close buttons,因为你必须添加喜欢while looprecords thenif conditionif(mysql-num_rows($result))

完整代码

<?php
    require_once("config.php");
    if (isset($_SESSION['username']) or $_SESSION['username']=== FALSE){
        header('location:login.php');
        exit();
    }
    $where = "";
    $searchCriteria = "";
    if (isset($_GET['search']) && $_GET['search'] != '') {
        $searchCriteria = mysql_real_escape_string($_GET['search']);
        $where = " WHERE subject LIKE '%" . $searchCriteria . "%'";
        $where .= " OR message like '%" . $searchCriteria . "%'";
    }
    $sql = "SELECT * FROM notes " . $where . " LIMIT 30";
    $result = mysql_query($sql);
?>
<!DOCTYPE html>
html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<a href="logout.php">Logout</a><br/><br/>
<div id="wrapper">
    <div id="add-message">
        <a href="add.php"><img src="images/add.png" title="Add"> Add a New   Message</a>
    </div>
    <br>
    <?php
    if(mysql_num_rows($result))
    {
        ?>
        <input type="button" id="opener" value="Open"/>
        <div id="playbox"> 
            <table id="general">
                <thead>
                    <tr>
                        <th class="general-header"></th>
                        <th class="general-subject">Subject</th>
                        <th class="general-message">Message</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <td colspan="4" class="general-foot"><input type="button" id="closer" value="Close"/></td>
                    </tr>
                </tfoot>
                <?php
                while ($row = mysql_fetch_assoc($result)) {
                ?>
                <?php echo $row['subject']; ?>

                <tbody>
                    <tr>
                        <td>
                            <a href="edit.php?id=<?php echo $row['id']; ?>"><img src="images/edit.png" title="Edit"> Edit</a>
                                                     &nbsp;|&nbsp; 
                            <a href="delete.php?id=<?php echo $row['id']; ?>"><img src="images/delete.png" title="Delete"> Delete</a>
                        </td>
                        <td class="subject"><?php echo $row['subject']; ?></td>
                        <td><?php if ($row['filename']!=''){?>
                            <img align="right" width="300px" src="<?php echo $row['filename']; ?>" />
                            <?php } ?>
                            <?php echo $row['message']; ?>
                        </td>
                    </tr>
                </tbody>
                <?php
                }

            ?>
            </table>
        </div>
        <?php
    }
    ?>
</div>
</body>
</html>

<script>
$(document).ready(function(){
    $("#playbox").hide();
    $("#opener").click(function(){
        $("#playbox").slideDown(600); 
    });
    $("#closer").click(function(){
        $("#playbox").slideUp(600); 
    });
});
</script>

如果你想toggle分开,那么你必须像这样编码,

HTML

让有两个类似Create的记录HTML使用while loop

<div class="contentSubject">
    <input type="button" class="btnOpener" value="Open" />
    <div class="playbox">
        <!--your table goes here-->
    </div>
</div>

<div class="contentSubject">
    <input type="button" class="btnOpener" value="Open" />
    <div class="playbox">
        //your table goes here
    </div>
</div>

脚本

<script>
    $(document).ready(function(){
        $(".playbox").hide();
        $(".btnOpener").click(function(){
            $(this).closest('.contentSubject')
                   .find(".playbox").slideDown(600); 
        });
        // same code for close
    });
</script>
于 2013-07-31T04:40:06.633 回答
0

请尝试该代码

$("#opener").live("click",function(){
    $("#playbox").slideDown(600); 
});
于 2013-07-31T04:58:19.843 回答