Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('display_errors',1);
  4. error_reporting(E_ALL);
  5.  
  6. mysql_connect('localhost', 'root', '');
  7.  
  8. mysql_select_db('testdb');
  9.  
  10. $result = mysql_query('select * from products');
  11.  
  12. $numrows = mysql_numrows($result);
  13.  
  14. //****************************************************************
  15. print "<table border = 3 style = width:400px>";
  16.  
  17.  
  18. for($i = 0; $i < $numrows; $i++)
  19. {
  20. $row = mysql_fetch_row($result);
  21.  
  22. print "<tr>";
  23.  
  24.  
  25. foreach($row as $cell)
  26. {
  27.  
  28. print "<td>";
  29. print $cell;
  30. print "</td>";
  31.  
  32.  
  33. }
  34. print "</tr>";
  35.  
  36.  
  37. }
  38.  
  39.  
  40.  
  41. print "</table>";
  42.  
  43.  
  44. mysql_close();
  45.  
  46. ?>
  47.  
  48. for($i = 0; $i < $numrows; $i++)
  49. {
  50. $row = mysql_fetch_row($result);
  51.  
  52. print "<tr>";
  53.  
  54.  
  55. foreach($row as $cell)
  56. {
  57.  
  58. print "<td>";
  59. print $cell;
  60. print "</td>";
  61. print "<td>";
  62. print "DELETE";
  63. print "</td>";
  64.  
  65. }
  66. print "</tr>";
  67.  
  68.  
  69. }
  70.  
  71. $result = mysql_query('select * from products');
  72.  
  73. print "<table>";
  74. while ($row = mysql_fetch_assoc($result)) {
  75. print "<tr><td>" . $row["name"] . "</td><td>" . $row["surname"] . "</td><td><a href="delete.php?id=<?php echo $row['id']; ?>">Delete</a></td></tr>";
  76. }
  77. print "</table>";
  78.  
  79. $id = $_GET["id"];
  80.  
  81. // Delete sql here. Do not forget to validate id here.
  82. header("Location: index.php"); // I assume, table page is this
  83.  
  84. ALTER TABLE `products` ADD COLUMN `id` INT AUTO_INCREMENT UNIQUE FIRST;
  85.  
  86. print "<table border = 3 style = width:400px>";
  87.  
  88.  
  89. for($i = 0; $i < $numrows; $i++)
  90. {
  91. $row = mysql_fetch_row($result);
  92. print "<tr>";
  93.  
  94. foreach($row as $cell)
  95. {
  96. print "<td>";
  97. print $cell;
  98. print "</td>";
  99. }
  100. print "<td><a href='delete.php?id=".$row["id"] ."' > delete </a> " ;
  101.  
  102. print "</tr>";
  103. }
  104.  
  105. $id = $_GET["id"];
  106. $delete = " DELETE from yourTable where id = ". $id ;
  107.  
  108. mysq_query ( $delete ) ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement