wpb Posted December 1, 2007 Share Posted December 1, 2007 This is probably more of an HTML question than a PHP one, but as I encountered it in a PHP context, I thought someone here might be able to offer advice... I have a MySQL database with records that each have a unique ID number. I use PHP to create a table listing all the records in the database, and I'd like to have an "Edit" and "Delete" button alongside each entry in the table. Rather than just using a link like this: <a href="editentry.php?id=1">Edit</a> <a href="editentry.php?id=2">Edit</a> <a href="editentry.php?id=3">Edit</a> etc. I was hoping to use an HTML button, as they stand out a bit more. As in: <a href="editentry.php?id=1"><button>Edit</button></a> etc. But I don't seem to be able to make a button into a link. Is this a genuine limitation? I know I could get this to work if I used forms, but I'd have to use a form for every single button in the table, as the ID numbers vary for each table row. I don't want to use Javascript's onclick handler, and I'd rather not create my own image that looks like a button. Any other ideas? Many thanks, Quote Link to comment Share on other sites More sharing options...
helraizer Posted December 1, 2007 Share Posted December 1, 2007 Hey wpb, You'd do it like so. <a href="editentry.php?id=1"><input type="button" value="Edit"></a> <a href="editentry.php?id=2"><input type="button" value="Edit"></a> And so on. I didn't test that but I think that's how you do it. You can also the use different images as buttons too. Sam Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2007 Share Posted December 1, 2007 More a self-imposed limitation than a genuine one. "I don't want to use any method that works (like checkboxes, javascript, images, multiple forms) so how can I do this?" The only option left that I can think of is make them all input type=submit buttons with the same name but give them all uniique values so you will know which one was clicked. [pre] [ Edit 998] [Delete 998] [ Edit 999] [Delete 999] [ Edit 1000] [Delete 1000] [/pre] where the numbers are the record ids or some other unique column such as username Quote Link to comment Share on other sites More sharing options...
wpb Posted December 1, 2007 Author Share Posted December 1, 2007 Thanks for the replies. Unfortunately, helraizer's suggestion doesn't work (not in IE, anyway). I thought I could just wrap a <button> tag up in a <a href> link, but it just doesn't seem to work. I realize it seems like I'm being contrary, Barand, but I don't want to use Javascript as my browser doesn't support it, and I was hoping to avoid putting a seperate form around every single button to cut down on the byte size of the page. Equally, it seems a shame to have to create a button png or something, when there's a perfectly good one in HTML 4 anyway with the <button> tag. Just a shame you don't seem to be able to make it into a link. Cheers, Will Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted December 1, 2007 Share Posted December 1, 2007 the <button> tag is taking the click event so you need to deal with that here is one way test.php <?php if (isset($_REQUEST['test'])) { echo "test = ".$_REQUEST['test']; } ?> <button onclick="location = 'test.php?test=1'">Click Me!</button> Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2007 Share Posted December 1, 2007 Unfortunately we are constrained by the "no javascript" clause. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted December 1, 2007 Share Posted December 1, 2007 what a PITA, fine... have it your way <?php if (isset($_REQUEST['test'])) { echo "test = ".$_REQUEST['test']; } ?> <form method="POST" action="test.php?test=1"> <button type=submit>Click Me!</button> </form> Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2007 Share Posted December 1, 2007 I'd use something like this, allowing only a single record to be selected for edit, but many for deletion <?php $names = array (1=>'Peter', 'Paul', 'Mary'); // array to simulate db data if (isset($_GET['sub'])) { switch ($_GET['sub']) { case "Edit": echo "Edit record id {$_GET['edit']}"; break; case 'Delete': $del_list = join(',', $_GET['del']) ; $sql = "DELETE FROM atable WHERE id IN ($del_list)"; echo $sql; break; } } ?> <form> <table> <tr> <td> ID </td> <td> Name </td> <td> Edit </td> <td> Delete </td> </tr> <?php foreach ($names as $id=>$name) echo" <tr> <td> $id </td> <td> $name </td> <td> <input type='radio' name='edit' value='$id'> </td> <td> <input type='checkbox' name='del[]' value='$id'> </td> </tr>"; ?> </table> <input type="submit" name="sub" value="Edit"> <input type="submit" name="sub" value="Delete"> </form> Quote Link to comment Share on other sites More sharing options...
wpb Posted December 1, 2007 Author Share Posted December 1, 2007 Thanks for all your suggestions. What a shame you can't just make a <button> into a link! Quote Link to comment Share on other sites More sharing options...
Aureole Posted December 1, 2007 Share Posted December 1, 2007 You could make it look like a link via CSS though it wouldn't be very... cross-browser. There seem to be a lot of issues when it comes to styling form elements. You can try it though. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 1, 2007 Share Posted December 1, 2007 Use a IMG as a button? Thanks for all your suggestions. What a shame you can't just make a <button> into a link! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 1, 2007 Share Posted December 1, 2007 Make the "button" in the href link using CSS - http://www.dynamicdrive.com/style/csslibrary/item/3d-css-buttons/ Quote Link to comment 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.