yanti Posted July 7, 2009 Share Posted July 7, 2009 ??? hi guys...just want to ask how am i delete current displayed data without remove it from database. for an example, i have select all data from database to be display. but i want to remove the row of displayed data without delete in database. so that the data will keep remain. any idea guys... Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/ Share on other sites More sharing options...
beyzad Posted July 7, 2009 Share Posted July 7, 2009 You mean to not display some data to users? Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870231 Share on other sites More sharing options...
AwptiK Posted July 7, 2009 Share Posted July 7, 2009 Do you want it to display all the rows except a specific one on the page load? If you're trying to display all the rows except for a specific one.. you could just put if($row['title'] == "Whatever title of what you don't want displayed") {} else { //all the others and the echos } in your foreach or while loop, which will print the ones you want and skip the row you don't. Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870234 Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 ok....maybe my question got confused..... eg. i display all data from database using column. now, i want to add delete column so that user can delete each row of data so that it wont appear in front end. but, the data still remain in database. Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870245 Share on other sites More sharing options...
beyzad Posted July 7, 2009 Share Posted July 7, 2009 Just add a field named 'valid' or anything. Set value to '1' for default. when the user delets that row, set the `valid` to '0' Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870248 Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 my current code is like this... <?php $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manisfm", $con); $result = mysql_query("SELECT * FROM topik ORDER BY id DESC"); echo "<table border='1'> <tr> <th>ID</th> <th>DATE / TIME</th> <th>SENDER</th> <th>TOPIK HANGAT</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['datetime'] . "</td>"; echo "<td>" . $row['sender'] . "</td>"; echo "<td>" . $row['topik'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> so where should i put it? Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870251 Share on other sites More sharing options...
beyzad Posted July 7, 2009 Share Posted July 7, 2009 <?php $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manisfm", $con); $result = mysql_query("SELECT * FROM topik WHERE `valid`='1' ORDER BY id DESC"); echo "<table border='1'> <tr> <th>ID</th> <th>DATE / TIME</th> <th>SENDER</th> <th>TOPIK HANGAT</th> <th>DELETE</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['datetime'] . "</td>"; echo "<td>" . $row['sender'] . "</td>"; echo "<td>" . $row['topik'] . "</td>"; echo "<td><a href='delete.php?id=" . $row['id'] . "'>DELETE THIS</a></td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> And in the delete.php write this: <?php $con = mysql_connect("","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("manisfm", $con); mysql_query("UPDATE `topik` SET `valid`='0' WHERE `id`='$_GET[id]'",$con); ?> Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870253 Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 but, does this means it will remove the data in database? i just want it not to be appear in front end. Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870254 Share on other sites More sharing options...
beyzad Posted July 7, 2009 Share Posted July 7, 2009 I didn't used any DELETE query. You are just updating your table. remember that you should use "WHERE `valid`='1'" in your query. Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870256 Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 ok...i had tried the code....but the DELETE THIS option does not appear....so i cant choose which row i want to be unseen.... Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870262 Share on other sites More sharing options...
beyzad Posted July 7, 2009 Share Posted July 7, 2009 You mean, you can't see "DELETE THIS" in your page?? Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870267 Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 yes Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870270 Share on other sites More sharing options...
beyzad Posted July 7, 2009 Share Posted July 7, 2009 I don't know why. but anyway, you should add 1 field in your table and use that to know which rows must be shown and which rows must not. Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870277 Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 ok..thanks anyway for ur help... Link to comment https://forums.phpfreaks.com/topic/165028-delete-only-displayed-data/#findComment-870279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.