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... Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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' Quote Link to comment 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? Quote Link to comment 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); ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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.... Quote Link to comment 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?? Quote Link to comment Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 yes Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
yanti Posted July 7, 2009 Author Share Posted July 7, 2009 ok..thanks anyway for ur help... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.