我有问题。我想在页面中显示每个“主题”(标题),而不仅仅是现在的第一个。当我添加新消息时,索引只显示第一个消息,只有当我点击“打开”按钮时,我才能看到所有消息。
有什么建议吗?
非常感谢。
这是代码:
<?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>
答案 0 :(得分:0)
我认为您应该使用mysql_num_rows
,并且您无需在open
中创建多个close
和buttons
while loop
,像records then
一样添加此内容,因为您必须添加if condition
之类的if(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>
|
<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>
<强> SCRIPT 强>
{{1}}
答案 1 :(得分:0)
请尝试该代码
$("#opener").live("click",function(){
$("#playbox").slideDown(600);
});