我遇到問題了。我想在頁面中顯示每個「主題」(標題),而不是像現在這樣顯示第一個。當我添加一條新消息時,index只顯示第一條消息,並且只有當我點擊「打開」按鈕時,我才能看到所有消息。PHP-jQuery正確顯示項目
有什麼建議嗎?
非常感謝。
這是德代碼:
<?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>
|
<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>
現在我只有一個爲所有科目「打開」和「關閉」按鈕。但是,是否可以爲顯示的每個主題設置「打開」和「關閉」按鈕。我知道你的方式更簡單合理,但我也需要這個其他選項。非常感謝。 – user2421425
嗨, 隨着上面的代碼,我可以同時顯示和隱藏「所有」的帖子,但我想要的是打開和隱藏分離。也就是說,每個帖子都有其相應的打開和隱藏按鈕。我需要在列表中單獨顯示帖子。謝謝。 – user2421425
@ user2421425測試上述答案我改變了它。 –