coder500 Posted August 6, 2008 Share Posted August 6, 2008 I am displaying the contents of a table. The contents are displayed in a for loop. On each row, I put 2 buttons also--- Update and Delete. I am not getting an idea how we can select the record if I press delete button near a record. for( $i = 0; $i < $row = mysql_fetch_array($result); $i++) { echo "<tr><td>"; echo $row['keyword']; echo "</td>"; echo "<td>"; echo $row['app_date']; echo "</td>"; echo "<td>"; echo $row['phno']; echo "</td><td>"; <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > </td><td><input type="submit" name="delete" value="Delete" /></td></tr> Any help please? Quote Link to comment Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Share Posted August 6, 2008 <?php echo $_SERVER['PHP_SELF']."?id=".$row['id'];?> ? Then use $_POST['id'] to select the id on submit Quote Link to comment Share on other sites More sharing options...
coder500 Posted August 6, 2008 Author Share Posted August 6, 2008 xstevey_bx , Does it mean that I have to add a field named 'id' to the table? Quote Link to comment Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Share Posted August 6, 2008 Yes, set it as the primary field and set it to auto incriment. Almost every table should have one as it is a good way to destinguish between rows. Quote Link to comment Share on other sites More sharing options...
coder500 Posted August 6, 2008 Author Share Posted August 6, 2008 I tried that. But the id is always 1, irrespective of the record. Quote Link to comment Share on other sites More sharing options...
xstevey_bx Posted August 6, 2008 Share Posted August 6, 2008 did you set the id value to auto incriment in the database and update the values for each record? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Also, why are you using a for() loop for MySQL results? I'm shocked that it even works because it barely makes logical sense, if it does. Use a while loop instead. Quote Link to comment Share on other sites More sharing options...
coder500 Posted August 6, 2008 Author Share Posted August 6, 2008 Hi All, Thanks for the hints. I fixed it. Dark Water, is it wrong to use for loop in mysql resul? Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Because a while loop would use less variables for that (no $i) which could possibly save some memory and I don't know why a for loop is even working there. Try: while ($row = mysql_fetch_assoc($result)) { } 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.