PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old September 3rd, 2002, 08:33 PM
chinni chinni is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 58 chinni User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Deleting the records in a table

hello all,
I display all the records from a table on a form.I used to update the fields and Now, i would like to delete record(s) in a table using the same form.
Here it goes how i really want to implement this one:

1.First, i dont want to delete the record in a table in a single-step.
2.(when i displayed the records from a table, i also display a check box at the end of each record).

3.Now, first, i want to check this box and click submit button.when i do this, i want to set a value to this row in the table(I've inserted a column called delete in the table)So, this column will have a value 0 or 1 when this row has been selected to delete.
4.After the value has been set, the form will show two buttons or images which has the values cancel delete or delete the record.

so, thatz it.

First thing, i would really like to do is to set the value to the delete column when the check box has been checked.

The records will be deleted only based on the column(delete), i.e the flag value.

If somebody has implemented such an application before, could you pls give me the code, if not atleast something similar to delete the records would be fine.I am able to do it with a simple delete statement in a single step but not in the way how i explained before.

For your reference here is my code which

hope somebody would be there to give assistance

Thanks in advance

To this code, i need to implement the delete functionality.

php Code:
Original - php Code
  1.  
  2. <?php
  3. //Database connection
  4.  
  5. if ($HTTP_POST_VARS){
  6.     /*-- the form was submitted, lets process it --*/
  7.     /*-- get a count of how many ids we have to process --*/
  8.     $cnt = count($HTTP_POST_VARS['id']);
  9.  
  10.     /*-- cycle through the arrays and update the database table --*/
  11.     for($cntr=0;$cntr<$cnt;$cntr++) {
  12.     if (!$HTTP_POST_VARS['attach'][$cntr]) $attach=0; else $attach=1;
  13.     if (!$HTTP_POST_VARS['detach'][$cntr]) $detach=0; else $detach=1;
  14.    
  15.     $sql = "UPDATE TBL_STATION SET ".
  16.         "HS_IPUI = '{$HTTP_POST_VARS['ipui'][$cntr]}', ".
  17.         "HS_TEI = '{$HTTP_POST_VARS['tei'][$cntr]}', ".
  18.         "HS_ATTACH = '$attach', ".
  19.         "HS_DETACH = '$detach', ".
  20.         "HS_AC = '{$HTTP_POST_VARS['ac'][$cntr]}' ".
  21.         "where HS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
  22.                    
  23.         $update_results = ibase_query($sql);
  24.     }
  25. }
  26.  
  27. /*-- get all records from the table --*/
  28.  
  29.     $select_sql = 'Select HS_ID, HS_DETACH, '.
  30.               'HS_ATTACH, HS_IPUI, HS_TEI, HS_AC from TBL_STATION';
  31.                       
  32.     $result_id = ibase_query($select_sql);
  33. ?>
  34.  
  35. <p class="hsnormalbold"><b>Edit details</b></p>
  36.     <hr style="line-height:100%; margin-top:0px; margin-bottom:0px;">
  37.     <form name="edit details" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
  38.         <table cellpadding="0" cellspacing="0" width="909" class="hsnormal">
  39.             <tr style="margin:0; padding:0;" align="left" valign="top" class="hsnormal">
  40.                 <td width="154">
  41.                     IPUI&nbsp;&nbsp;&nbsp;
  42.                 </td>
  43.                 <td width="154">
  44.                     TEI
  45.                 </td>
  46.                 <td width="65">
  47.                     Attach
  48.                 </td>
  49.                 <td width="155">
  50.                     Detach
  51.                 </td>
  52.                 <td width="96">
  53.                     AC
  54.                 </td>
  55.                 <td width="96">
  56.                     Delete
  57.                 </td>
  58.                 </tr>
  59. <?php
  60.         
  61.         $counter=0;
  62.         $old_values=null;
  63.    
  64.         while ($row = ibase_fetch_object($result_id)) {
  65.         $attach=$row->HS_ATTACH;
  66.         $detach=$row->HS_DETACH;
  67.         $ipui=$row->HS_IPUI;
  68.         $tei=$row->HS_TEI;
  69.         $ac=$row->HS_AC;
  70.        
  71.         /*-- output this row in the table --*/
  72. ?>
  73.             <tr style="margin:0; padding:0;" align="left" valign="top" class="hsnormal">
  74.                 <td width="156" height="23">
  75.                     <input type="text" name="ipui[<?=$counter?>]" value="<?=$ipui?>">
  76.                 </td>
  77.                 <td width="154" height="23">
  78.                     <input type="text" name="tei[<?=$counter?>]" value="<?=$tei?>">
  79.                 </td>
  80.                 <td width="69" height="23">
  81.                     <input type="checkbox" name="attach[<?=$counter?>]" value="1"<? if ($attach==1)echo "checked";?>>
  82.                 </td>
  83.                 <td width="65" height="23">
  84.                     <input type="checkbox" name="detach[<?=$counter?>]" value="1" <? if ($detach==1)echo "checked";?>>
  85.                 </td>
  86.                 <td width="156" height="23" align="left" valign="top">
  87.                     <input type="text" name="ac[<?=$counter?>]" value="<?=$ac?>">
  88.                 </td>
  89.                 <td width="65" height="23">
  90.                     <input type="checkbox" name="delete" value="1">->>When this check box is checked, i want the delete column t ó be set to 1 for the selected row
  91.                 </td>
  92.             </tr>
  93.     <?php
  94.        
  95.         $old_values.='    <input type="hidden" name="id['.$counter.']" value="'.$row->HS_ID.'">
  96.         ';
  97.         $counter++;
  98.     }
  99.     ?>
  100.         </table>
  101.         <?=$old_values?>
  102.         <input type="submit" name="submit" value="Update">
  103.         &nbsp;&nbsp;
  104.         <input type="hidden" value="Reset">
  105.     </form>
  106.     <p class="hsnormal">&nbsp;</p>
  107.     <p class="hsnormal">&nbsp;</p>
  108.     <p class="hsnormal">&nbsp;</p>
  109.     <p class="hsnormal">&nbsp;</p>
  110.     <p class="hsnormal">&nbsp;</p>
  111.     <p class="hsnormal">&nbsp;</p>
  112.     <p class="hsnormal">&nbsp;</p>
  113.     <p class="hsnormal">&nbsp;</p>
  114. </body>
  115. </html>
  116.  







Reply With Quote
  #2  
Old September 3rd, 2002, 08:55 PM
Nimco Nimco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 132 Nimco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to Nimco
RE: Deleting the records in a table

Wasn't this answered in: ?

http://codewalkers.com/forum/index....6&realm=default

OK, I'm just going to copy out your code below with colour coding on so that it is easier to read - then I'll see if I can modify it where necessary for you.
--------

php Code:
Original - php Code
  1.  
  2. <?php
  3. //Database connection
  4.  
  5. if ($HTTP_POST_VARS){
  6. /*-- the form was submitted, lets process it --*/
  7. /*-- get a count of how many ids we have to process --*/
  8. $cnt = count($HTTP_POST_VARS['id']);
  9.  
  10. /*-- cycle through the arrays and update the database table --*/
  11. for($cntr=0;$cntr<$cnt;$cntr++) {
  12. if (!$HTTP_POST_VARS['attach'][$cntr]) $attach=0; else $attach=1;
  13. if (!$HTTP_POST_VARS['detach'][$cntr]) $detach=0; else $detach=1;
  14.  
  15. $sql = "UPDATE TBL_STATION SET ".
  16. "HS_IPUI = '{$HTTP_POST_VARS['ipui'][$cntr]}', ".
  17. "HS_TEI = '{$HTTP_POST_VARS['tei'][$cntr]}', ".
  18. "HS_ATTACH = '$attach', ".
  19. "HS_DETACH = '$detach', ".
  20. "HS_AC = '{$HTTP_POST_VARS['ac'][$cntr]}' ".
  21. "where HS_ID = {$HTTP_POST_VARS['id'][$cntr]}";
  22.  
  23. $update_results = ibase_query($sql);
  24. }
  25. }
  26.  
  27. /*-- get all records from the table --*/
  28.  
  29. $select_sql = 'Select HS_ID, HS_DETACH, '.
  30. 'HS_ATTACH, HS_IPUI, HS_TEI, HS_AC from TBL_STATION';
  31.  
  32. $result_id = ibase_query($select_sql);
  33. ?>
  34.  
  35. <p class="hsnormalbold"><b>Edit details</b></p>
  36. <hr style="line-height:100%; margin-top:0px; margin-bottom:0px;">
  37. <form name="edit details" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="POST">
  38. <table cellpadding="0" cellspacing="0" width="909" class="hsnormal">
  39. <tr style="margin:0; padding:0;" align="left" valign="top" class="hsnormal">
  40. <td width="154">
  41. IPUI&nbsp;&nbsp;&nbsp;
  42. </td>
  43. <td width="154">
  44. TEI
  45. </td>
  46. <td width="65">
  47. Attach
  48. </td>
  49. <td width="155">
  50. Detach
  51. </td>
  52. <td width="96">
  53. AC
  54. </td>
  55. <td width="96">
  56. Delete
  57. </td>
  58. </tr>
  59. <?php
  60.  
  61. $counter=0;
  62. $old_values=null;
  63.  
  64. while ($row = ibase_fetch_object($result_id)) {
  65. $attach=$row->HS_ATTACH;
  66. $detach=$row->HS_DETACH;
  67. $ipui=$row->HS_IPUI;
  68. $tei=$row->HS_TEI;
  69. $ac=$row->HS_AC;
  70.  
  71. /*-- output this row in the table --*/
  72. ?>
  73. <tr style="margin:0; padding:0;" align="left" valign="top" class="hsnormal">
  74. <td width="156" height="23">
  75. <input type="text" name="ipui[<?=$counter?>]" value="<?=$ipui?>">
  76. </td>
  77. <td width="154" height="23">
  78. <input type="text" name="tei[<?=$counter?>]" value="<?=$tei?>">
  79. </td>
  80. <td width="69" height="23">
  81. <input type="checkbox" name="attach[<?=$counter?>]" value="1"<? if ($attach==1)echo "checked";?>>
  82. </td>
  83. <td width="65" height="23">
  84. <input type="checkbox" name="detach[<?=$counter?>]" value="1" <? if ($detach==1)echo "checked";?>>
  85. </td>
  86. <td width="156" height="23" align="left" valign="top">
  87. <input type="text" name="ac[<?=$counter?>]" value="<?=$ac?>">
  88. </td>
  89. <td width="65" height="23">
  90. <input type="checkbox" name="delete" value="1">->>When this check box is checked, i want the delete column t ó be set to 1 for the selected row
  91. </td>
  92. </tr>
  93. <?php
  94.  
  95. $old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->HS_ID.'">
  96. ';
  97. $counter++;
  98. }
  99. ?>
  100. </table>
  101. <?=$old_values?>
  102. <input type="submit" name="submit" value="Update">
  103. &nbsp;&nbsp;
  104. <input type="hidden" value="Reset">
  105. </form>
  106. <p class="hsnormal">&nbsp;</p>
  107. <p class="hsnormal">&nbsp;</p>
  108. <p class="hsnormal">&nbsp;</p>
  109. <p class="hsnormal">&nbsp;</p>
  110. <p class="hsnormal">&nbsp;</p>
  111. <p class="hsnormal">&nbsp;</p>
  112. <p class="hsnormal">&nbsp;</p>
  113. <p class="hsnormal">&nbsp;</p>
  114. </body>
  115. </html>

Reply With Quote