0

i need to delete / edit selected row from table with checkbox i am showing a table from my database

this is the table

<table width="100%" class="table-responsive" style="border: solid;border-color: white;">
<tr style="background: #737375;color: white;">
<td></td>
<td align="center" style="border: solid;border-color: white;">Accomodation</td>
<td style="border: solid;border-color: white;" align="center">Address</td><br>
<td style="border: solid;border-color: white;" align="center">Rooms</td>
<td align="center" style="border: solid;border-color: white;">Status</td>
<td align="center" style="border: solid;border-color: white;">Delete</td>
<td align="center" style="border: solid;border-color: white;">Edit</td>
</tr>

filling the table

<?php 
mysql_connect("localhost","","");
$link=mysql_select_db("orangeom_orangedb");
$req="select * from accomodation order by accid";
$res=mysql_query($req);
$i=1;
while ($ligne1=mysql_fetch_object($res))
{ $i=$i+1;
?>
<tr <?php if( bcmod($i, 2)==0) {echo "bgcolor='#FFCC99'"; } ?> >
<td style="border: solid;border-color: white;"><div class="radio" align="center">
<label><input type="radio" name="radio[]" id="radio[]" value="<?php echo $ligne1->accid;?>"></label>
</div></td> 
<td style="border: solid;border-color: white;"><input name="uid" type="hidden" id="uid" value="<?php echo $ligne1->accid;?>"/><?php echo $ligne1->name;?></td>
<td style="border: solid;border-color: white;"><?php echo $ligne1->address;?></td>
<td style="border: solid;border-color: white;"><?php echo $ligne1->rooms;?></td>
<?php
    if($ligne1->status =='1')
    {?>
    <td style="border: solid;border-color: white;"><div align="center"><img src="../../images/Active.png"  width="16px" height="16px"/></div></td>
    <?php
    }
    else
    {?>
    <td style="border: solid;border-color: white;"><div align="center"><img src="../../images/NotActive.png"  width="16px" height="16px"/></div></td>
    <?php
    }?>
    <td style="border: solid;border-color: white;"><div align="center"><a onclick="return confirm('Are you sure to delete ???');" href='delAccomodation.php?accid=<?php echo $ligne1->tripID; ?>&accid=<?php echo $ligne1->accid; ?>'><img src='../../images/Delete.png' width='16' height='16'/></a></div></td>
    <td style="border: solid;border-color: white;"><div align="center"><a href='interAccomodation.php?accid=<?php echo $ligne1->accid; ?>&accname=<?php echo $ligne1->name;?>&accaddress=<?php echo $ligne1->address; ?>&accrooms=<?php echo $ligne1->rooms; ?>&accstat=<?php echo $ligne1->status;?>'><img src='../../images/Edit.png' width='16' height='16' /></a></div></td>
</tr>
<?php }
mysql_close();?>
</table>

i want select one row and delete by an image

<img src="../../images/delete.png" id="delete" width="16px" height="16px"/>
Hichem
  • 1
  • 3
  • 2
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly May 15 '17 at 09:16
  • 2
    You might also want to change that password now. – Jan May 15 '17 at 09:17
  • 1
    So basically you are asking us to write the PHP code to do the delete. Right? – RiggsFolly May 15 '17 at 09:23
  • i have the delete code for each row but i want to do it outside the table – Hichem May 15 '17 at 09:24
  • Well you already have the anchor tag in place to do the delete, so I dont understand what you are asking – RiggsFolly May 15 '17 at 09:25
  • i want to remove the delete and edit buttons from each row i will delete using a button outside the table when the checkbox is checked – Hichem May 15 '17 at 09:30
  • well you need to start by adding some checkboxes to the HTML with the item IDs as values. Then on the server, when the delete button is pressed, loop through all the post variables and find the ones that are present (unchecked checkboxes are not even sent in the POST variables). Then use those values to include in your delete query. – ADyson May 15 '17 at 09:36

0 Answers0