Delete function help!


#1

I want to delete the data from the web pages but I do not want to delete it also from the database.
How should I start it?


#2

Can you be more specifically?


#3

I have one table call student inside have some information of the student, but now I need to delete one of the student’s name and details. However this table was store in Mysql now I want to delete the one of the student row but I do not want delete the database data, but only want to delete the data from the web page, because I have one page is list down all the data from the student table.


#4

i assume now that your table has one primary cell index with auto_increment and is called id
so if you wanna take something out you have to know the stdent id :slight_smile:

[php]
$query = mysql_query("SELECT * FROM student where student_id!=’$id_of_your_student’ ");
[/php]

let me know if this helpes you any further


#5

After how? What is your meaning? I want delete data but do not want delete from the database also.
I can delete data from the database but I do not want this. I want the data remain in the database but do not to display it in the web page only.


#6

this will remain in your database it will tell the SQL to select all users he can find in the database but the one you dont want to.

someting like “Give me all you got on students except the student X”

or you can also modify the while in your php code with one if condition

[php]if($student_id != ‘your_selected_id’){
echo “Your_table”;[/php]


#7

Please post the PHP-Code wich gets you the table with the students information and i will try to modify this for you :slight_smile:


#8

[php]


Delete data

<body>

<?php
// Set to 1 for debugging
$DEBUG = 0;

// Connect to database server
mysql_connect("localhost", "root", "111") or die (mysql_error ());

// Select database
mysql_select_db("data") or die(mysql_error());

$delete_id =$_GET['delete_id '];

// The SQL statement that deletes the record
$strSQL = "DELETE * FROM student WHERE delete_id = $delete_id ";
$result = mysql_query($strSQL);

// debuggiing
	if ($DEBUG == 1)
	{
		echo 	"<BR> DEBUG: ".
			"result: |".$result."| ".
			"query: |".$strSQL."| <BR>";
	}	
	

// Close the database connection
mysql_close();
?>

<h1>Record is deleted!</h1>

</body>
</html>
	
[/php]

#9

this is not the code which shows you your students table, this is one code wich removes something from your database.

You have to add one more column to your students table, named deleted with a standard value of 0, which means every entry you make into your database is NOT deleted from the table AND it WILL be showed in your table.

Then you can change the value of deleted to 1 and the respective student will be not more available in your table, but it will stay into your database, it will not be deleted from your databse, because you will select just the students wich have the value of deleted equals 0

The ones which haves 1 will be not be showed!

So here is a example

id | student_name | student_age | deleted
1 chris 18 years 0
2 alex 20 years 1

php code to change delete value for an specific id

[php]
$student_id = $_GET[‘delete_id’];
$change_value = “UPDATE student SET deleted=‘1’ where student_id=’$student_id’”;
$do_query = mysql_query($change_value) or die (mysql_error () );
if(@$do_query){
echo “Record deleted from table”;
}else{
echo “Error”;
}
[/php]

Now how you get too see all students wich are suposed to be shown:

[php]
echo"

";

$query = “SELECT * FROM students WHERE deleted=‘0’”;
$do_query=mysql_query($query);
while($data = mysql_fetch_array($do_query)){
$id = $data[id]; # $data[‘here_should_be_your_table_id_name’]; #
$student_name = $data[student_name];
$student_age = $data[student_age];
echo "

"; } echo "
delete name student
delete from table $student_name $student_age
"; [/php]

You have to test it i havent tested this yet but it should work and dont forget to add a column in your students table (in your database) named deleted


#10

Thanks…
I solved it.


#11

LOL, WHO solved it??? LOL…


#12

my pleasure.
well Alex, together have we solved it :slight_smile: