Carlos Oulman
Carlos Oulman

Reputation: 21

How to delete a certain row from my mysql table?

I am trying to create a school closings system with a database so that we don't have to put all the schools in manually every time we need to update it.

What I am wanting to do is have all the schools in the database but only show schools that have a status other then Open. So for example, if School 1 is Open but School 2 is cancelled I only want to show School 2.

I would also like to be able to show a message of all schools are set to Open in the status column.

<html>
<?php

//make connection to database
mysql_connect('***', '***', '***');

//select database
mysql_select_db('***');

$sql="SELECT * FROM Schools";

$records=mysql_query($sql);

?>

<head>
<title>School Closings</title>
</head>
<body>

<table width="600px" border="1px" cellspacing="0px" cellpadding="3px">
<tr>

<th>Name</th>
<th>Status</th>
<th>Comments</th>
</tr>

<?php

while($Schools=mysql_fetch_assoc($records)) {

echo "<tr>";

echo "<td>".$Schools['Name']."</td>";

echo "<td>".$Schools['Status']."</td>";

echo "<td>".$Schools['Comments']."</td>";

echo "</tr>";

}//end while

?>

</table>
</body>
</html>

Upvotes: 0

Views: 75

Answers (3)

Redbeard011010
Redbeard011010

Reputation: 964

I don't think you want to delete any rows at all. I think you want to DISPLAY only certain rows, and exclude others from being displayed. In accordance with this assumption:

Just modify the query to include a where clause that selects only results with the status 'closed' (or however you flag this status):

SELECT name, status, comments FROM schools WHERE status <> 'open';

Or WHERE closed = 1;

whatever the case may be (depending of course on your table structure)

Upvotes: 0

pradeep
pradeep

Reputation: 592

Just add a WHERE clause in your query to filter the status.

$sql="SELECT * FROM Schools WHERE `status` = 'cancelled'";

and don't use the * in SELECT statement, specify the column names in your code !

Upvotes: 0

Muhammad Haseeb
Muhammad Haseeb

Reputation: 1341

$sql=SELECT * FROM schools WHERE status = 'Cancelled'; Use this query, you don't need to delete the records, this query will fetch the records of schools that are not open or cancelled

Upvotes: 2

Related Questions