Jump to content

How to insert checkbox in my php table data


shwetapandit

Recommended Posts

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>";
?>
 

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.