shwetapandit Posted September 18, 2013 Share Posted September 18, 2013 i want that as my program prints all the records from tthe table in columns i want a checkbox in front of every row so that if a user want to delete that particular row then he can click on that checkbox. how can i do this.......Here is the snippet. <?php$conn=mysqli_connect("localhost","","","test");echo"connected";$query="SELECT * FROM student ORDER BY roll_no";$res=mysqli_query($conn,$query);$row=(mysqli_fetch_array($res,MYSQLI_ASSOC));echo "roll_no".$row['roll_no'];echo "subject".$row['subject'];echo "marks".$row['marks']."<br/>";echo "<table border='1'>";echo "<tr> <th>ROLL_NO</th> <th>SUBJECT</th> <th>MARKS</th></tr>";while($row = mysqli_fetch_array($res,MYSQL_ASSOC)){ echo"<tr><td>";echo $row['roll_no'];echo "</td><td>";echo $row['subject'];echo "</td><td>";echo $row['marks'];echo "</td></td>";//echo "<td><input type="checkbox"></td>"//echo "</td></tr>"}echo "</table>";?> Quote Link to comment https://forums.phpfreaks.com/topic/282242-how-to-insert-checkbox-in-my-php-table-data/ Share on other sites More sharing options...
fastsol Posted September 18, 2013 Share Posted September 18, 2013 Do you have a unique ID for each row in the db? If so what is the column named? If not then you should put one in there to make this more fool proof. Let me know and I can likely help. Quote Link to comment https://forums.phpfreaks.com/topic/282242-how-to-insert-checkbox-in-my-php-table-data/#findComment-1450078 Share on other sites More sharing options...
arvnd86 Posted September 18, 2013 Share Posted September 18, 2013 Hi,, If you have a unique id you can give it in check box value... <?php$conn=mysqli_connect("localhost","","","test");echo"connected";$query="SELECT * FROM student ORDER BY roll_no";$res=mysqli_query($conn,$query);$row=(mysqli_fetch_array($res,MYSQLI_ASSOC));echo "roll_no".$row['roll_no'];echo "subject".$row['subject'];echo "marks".$row['marks']."<br/>";echo "<table border='1'>";echo "<tr> <th>ROLL_NO</th> <th>SUBJECT</th> <th>MARKS</th> <th>Select</th></tr>";while($row = mysqli_fetch_array($res,MYSQL_ASSOC)) { echo"<tr><td>";echo $row['roll_no'];echo "</td><td>";echo $row['subject'];echo "</td><td>";echo $row['marks'];echo "</td>";echo "<td><input type=\"checkbox\" name=\"name\" value=\"$row[id]\"></td>";echo "</tr>";}echo "</table>";?> Quote Link to comment https://forums.phpfreaks.com/topic/282242-how-to-insert-checkbox-in-my-php-table-data/#findComment-1450090 Share on other sites More sharing options...
AbraCadaver Posted September 18, 2013 Share Posted September 18, 2013 Using the concept above, likely you would use an array. Also, you need to wrap the table in a form and have a delete/submit button: echo "<td><input type=\"checkbox\" name=\"records[]\" value=\"$row[id]\"></td>"; Then on the receiving page you could implode() and use in an IN clause: $ids = implode(',', array_map('intval', $_POST['records'])); //DELETE * FROM table_name WHERE id IN ($ids) Quote Link to comment https://forums.phpfreaks.com/topic/282242-how-to-insert-checkbox-in-my-php-table-data/#findComment-1450119 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.