Jump to content

Delete rows from while statment


nezbo

Recommended Posts

Hi all

 

I have this code and i want to beable to when i click the delete link to delete the row that is selected in the database?

 

Any help please?

 

$result = mysql_query("SELECT * FROM person ORDER BY UserName ASC");

echo "<table border=1 align=center>";

echo "<tr><td colspan=8 align=center><h2>All users registered with the system.</h2><tr><td>";

while ($row = mysql_fetch_array($result))

{

echo "<tr><td align=left><a href=editUser.php?user_identifier=$row[CallID] >$row[CallID] </a>" .

"</td><td align=left>" . $row['UserName'] .

"</td><td align=left>" . $row['FullName'] .

"</td><td align=left>" . $row['EmailAddress'] .

"</td><td align=left>" . $row['ContactNumber'] . 

"</td><td align=left>" . $row['UserLevel'] .

"</td><td align=left> <a href=#>Delete</a>" . "</td></tr>";

}

echo "</table>";

 

Neil

Link to comment
https://forums.phpfreaks.com/topic/58379-delete-rows-from-while-statment/
Share on other sites

Well im guesing that your 'CallID' field is a unique field? If so, just pass that into the query string, as you do for your editUser.php page, and delete the row:

 

<?php
$id = $_GET['CallID'];
mysql_query("DELETE FROM `person` WHERE `CallID`='$id'") or die(mysql_error());
?>

cool cheers

 

does this mean i need to creat a form type of thing to instrd of using a <a href.... ?

 

 

 

Well im guesing that your 'CallID' field is a unique field? If so, just pass that into the query string, as you do for your editUser.php page, and delete the row:

 

<?php
$id = $_GET['CallID'];
mysql_query("DELETE FROM `person` WHERE `CallID`='$id'") or die(mysql_error());
?>

No not at all. Get variables are passed to a page in the URL. If you specify the form method as get, all it actually does it put the contents of the form in the url.

 

You would make your links something like:

 

echo "<a href='deleteuser.php?id=$row[CallID]'>$row[CallID]</a>";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.