ohkered Posted January 5, 2011 Share Posted January 5, 2011 hi guys, Basically, what I did was i displayed my database information by a table. on which on the last column there's 2 link, which is edit and delete. My question is what code should i put that when I click on the edit or delete link, so that it can indicate that particular data (or ID) has been selected (or stored) ? sorry for my poor english. hope u guys understand what i need. thanks and help pls SQLversion: 5.5.8 <?php //connects to database require('connect.php'); //select table $select = mysql_query("SELECT * FROM studentinfo") or die('No table exist!'); $numrows = mysql_num_rows($select); echo <<<EOM <table border='1'> <tr> <th>Student Number</th> <th>First Name</th> <th>Last Name</th> <th>Email Address</th> <th>Phone Number</th> <th>Actions</th> </tr> EOM; while ($row = mysql_fetch_assoc($select)) { echo <<<EOM <tr> <td>{$row['StudentNumber']}</td> <td>{$row['FirstName']}</td> <td>{$row['LastName']}</td> <td>{$row['EmailAddr']}</td> <td>{$row['PhoneNumber']}</td> <td><a href='update.php'>Edit</a> <a href='delete.php'>Delete</a></td> </tr> EOM; } echo <<<EOTABLE </table> EOTABLE; ?> Quote Link to comment https://forums.phpfreaks.com/topic/223439-edit-and-delete-data-in-a-php-table-using-a-link/ Share on other sites More sharing options...
requinix Posted January 5, 2011 Share Posted January 5, 2011 I'm guessing the StudentNumber is unique? Something by which you can identify one and only one record in the table? Example: update.php?sn=(student number goes here) if (isset($_GET["sn"])) { $sn = (int)$_GET["sn"]; // do whatever } else { // no student number given. redirect someplace? show an error message? } Quote Link to comment https://forums.phpfreaks.com/topic/223439-edit-and-delete-data-in-a-php-table-using-a-link/#findComment-1155032 Share on other sites More sharing options...
ohkered Posted January 5, 2011 Author Share Posted January 5, 2011 I have a recordID in my database which is unique, and my studentID is Index. which is, yeah unique. ok i'll look into your codes later, gotta rest. thanks requinix! Quote Link to comment https://forums.phpfreaks.com/topic/223439-edit-and-delete-data-in-a-php-table-using-a-link/#findComment-1155124 Share on other sites More sharing options...
ohkered Posted January 5, 2011 Author Share Posted January 5, 2011 $sn = (int)$_GET["sn"]; my student ID consist of int and char, what should i replace with int? thanks! the code is almost working. *edit:ahh change it to 'String' . Quote Link to comment https://forums.phpfreaks.com/topic/223439-edit-and-delete-data-in-a-php-table-using-a-link/#findComment-1155398 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.