PHP-jQuery Displaying items properly -
i have problem. want display every "subject" (titles) in page , not first 1 now. when add new message, index displays first one, , when click on "open" button can see messages.
any suggestion?
many thanks.
this de code:
<?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 = " subject '%" . $searchcriteria . "%'"; $where .= " or message '%" . $searchcriteria . "%'"; } $sql = "select * 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 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>
i think should use mysql_num_rows
, don't have need create many open
, close
buttons
in while loop
, add once if records then
, have add if condition
if(mysql-num_rows($result))
full code
<?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 = " subject '%" . $searchcriteria . "%'"; $where .= " or message '%" . $searchcriteria . "%'"; } $sql = "select * 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 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>
if want toggle
separately have code like,
html
let there 2 records create
html
using 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
<script> $(document).ready(function(){ $(".playbox").hide(); $(".btnopener").click(function(){ $(this).closest('.contentsubject') .find(".playbox").slidedown(600); }); // same code close }); </script>
Comments
Post a Comment