Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正确显示项目的PHP jQuery_Php_Jquery - Fatal编程技术网

正确显示项目的PHP jQuery

正确显示项目的PHP jQuery,php,jquery,Php,Jquery,我有个问题。我想显示页面中的每个“主题”(标题),而不是像现在这样只显示第一个主题。当我添加一条新消息时,“索引”仅显示第一条消息,只有当我单击“打开”按钮时,我才能看到所有消息 有什么建议吗 非常感谢 这是de代码: <?php require_once("config.php"); if (isset($_SESSION['username']) === FALSE){ header('location:login.php'); exit(); } $where = "

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

有什么建议吗

非常感谢

这是de代码:

<?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>

主题
消息
|  
" />
$(文档).ready(函数(){
$(“#playbox”).hide();
$(“#开场白”)。单击(函数(){
$(#playbox”)。向下滑动(600);
});
$(“#关闭”)。单击(函数(){
$(#playbox”).slideUp(600);
});
});

我认为你应该使用
mysql\u num\u行
,你不需要在
while loop
中创建许多
打开
关闭
按钮,只需像if
记录
那样添加一次,因为你必须添加
if条件
if(mysql-num\u行)($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>
脚本

<script>
    $(document).ready(function(){
        $(".playbox").hide();
        $(".btnOpener").click(function(){
            $(this).closest('.contentSubject')
                   .find(".playbox").slideDown(600); 
        });
        // same code for close
    });
</script>

$(文档).ready(函数(){
$(“.playbox”).hide();
$(“.btnOpener”)。单击(函数(){
$(this).closest(“.contentSubject”)
.find(“.playbox”).slideDown(600);
});
//关闭时使用相同的代码
});
请尝试该代码

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

现在我只有一个“打开”和“关闭”按钮用于所有主题。但是,是否有可能为每个主题显示一个“打开”和“关闭”按钮。我知道你的方式更简单合理,但我也需要这个其他选项。非常感谢。嗨,有了上面的代码,我可以显示和隐藏“所有”“同时显示帖子,但我要的是分开打开和隐藏。也就是说,每个帖子都有各自的“打开”和“隐藏”按钮。我需要在列表中单独显示帖子。谢谢。@user2421425测试上面的答案我已经更改了它。”。
$("#opener").live("click",function(){
    $("#playbox").slideDown(600); 
});