PDA

View Full Version : How to display rows of data with edit/delete links?



Emkay
11-03-2009, 11:58 PM
If I wanted to list a bunch of records in a database through a table, and also have edit/delete links for each record on the side, how would I go about coding something like this? I know I have to use a while or foreach loop to display the records but how to I add the relevant links for each record?

In context, I am trying to display a list of clients, with edit and delete links which will allow me to edit information for that client or delete the whole client.

Thanks in advance.

met
11-04-2009, 12:14 AM
$qry = mysql_query('SELECT * FROM tblClients'):
while($r=mysql_fetch_array($qry)) {

echo '<a href="edit.php?client='.$r['client_id'].'">Edit ' . $r['client_name'] . '</a> | ';
echo '<a href="delete.php?client='.$r['client_id'].'">Edit ' . $r['client_name'] . '</a>';
}


use get to access the client. SELECT * FROM table WHERE clientID = $_GET['client_id']. update/delete as necessary.

bucket
11-04-2009, 12:29 AM
Im doing the exact same thing at the moment!

Give me like 10 minutes and il give u it.

tomws
11-04-2009, 03:01 AM
use get to access the client. SELECT * FROM table WHERE clientID = $_GET['client_id']. update/delete as necessary.

Congratulations! You just pwnd his db!

I understand trying to shoot off a quick answer as I do that myself, but this is a textbook example of how not to write a query. Do him a favor and toss in the mysql_real_escape_string line anyway.

Emkay
11-04-2009, 05:05 PM
Thanks but how do I actually code the functionality of the edit/delete links though? How would it know which to edit or delete once it clicks on the link?

tomws
11-04-2009, 05:13 PM
That portion of met's code is workable. Notice that each link is keyed with the client's unique id from the database.