Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. <?php
  2. //1.Create a database connection
  3. $dbhost = "localhost";
  4. $dbuser ="widget_cms";
  5. $dbpass="12605532y";
  6. $dbname = "widget_crop";
  7. $connection = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
  8.  
  9. //test if connection occured
  10. if(mysqli_connect_errno()){
  11. die("Database connection failed !".
  12. mysqli_connect_error().")".mysqli_connect_errno().")"
  13. );
  14. }
  15. ?>
  16. <?php
  17. $menu_name = ""Edit me"";
  18. $position=4;
  19. $visible = 1;
  20. // Often these are form values in POST
  21. // 2.Perform a db query
  22. $query ="INSERT INTO ";
  23. $query .="subjects (menu_name,position,visible) ";
  24. $query .="VALUES($menu_name,$position,$visible);rn";
  25. $query .="SELECT *";
  26. $query .="FROM subjects ";
  27. $query .="WHERE visible = 1 ";
  28. $query .="ORDER BY position ASC;";
  29. echo $query;
  30. $result = mysqli_multi_query($connection,$query);
  31. if(!$result){
  32. die("Database query failed !");
  33. }
  34. ?>
  35. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  36. "http://www.w3.org/TR/html4/loose.dtd">
  37. <style>
  38. body{
  39. font-family:tahoma;
  40. font-size:0.75em;
  41. }
  42. table{
  43. border-collapse: collapse;
  44. }
  45. td{
  46. padding-top:5px;
  47. padding-bottom:5px;
  48. padding-right:15px;
  49. padding-left:15px;
  50. background: lightblue;
  51. border-color: white;
  52. }
  53.  
  54. </style>
  55.  
  56. <html lang="en">
  57. <head>
  58. <title>untitled</title>
  59. </head>
  60. <body>
  61. <table border="2">
  62. <?php
  63. while($row = mysqli_fetch_assoc($result)){
  64. // 3. Use returned Data
  65. // output date from each row
  66. echo "<tr>";
  67. echo"<td>". $row["id"] ."</td>";
  68. echo"<td>". $row["menu_name"] ."</td>";
  69. echo"<td>". $row["position"] ."</td>";
  70. echo"<td>". $row["visible" ]."</td>";
  71. echo "</tr>";
  72. }
  73. ?>
  74. </table>
  75. <?php
  76. // 4. release the returned data
  77. mysqli_free_result($result);
  78. ?>
  79. </body>
  80. </html>
  81. <?php
  82. // 5. Close the connection
  83. mysqli_close($connection);
  84. ?>
  85.  
  86. do {
  87. /* store first result set */
  88. if ($result = mysqli_store_result()) {
  89. while ($row = $result->fetch_row()) {
  90. if(!empty($row["id"])){
  91. echo "<tr>";
  92. echo"<td>". $row["id"] ."</td>";
  93. echo"<td>". $row["menu_name"] ."</td>";
  94. echo"<td>". $row["position"] ."</td>";
  95. echo"<td>". $row["visible" ]."</td>";
  96. echo "</tr>";
  97. }
  98. }
  99. $result->free();
  100. }
  101. /* print divider */
  102. if (mysqli_more_results()) {
  103. printf("-----------------n");
  104. }
  105. } while (mysqli_next_result());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement