Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.69 KB | None | 0 0
  1. <?php
  2. /*
  3. echo "<center>";
  4. echo "<h1>Contacts:</h1>";
  5. echo "<style>";
  6. echo 'table {';
  7. echo 'font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;';
  8. echo 'width:100%;';
  9. echo 'border-collapse:collapse;';
  10. echo 'font-size: 1.2em;';
  11. echo 'border: 1px solid white;';
  12. echo 'padding: 3px 7px 2px 7px;';
  13. echo 'font-size: 1.4em;';
  14. echo 'text-align: left;';
  15. echo 'padding-top: 5px;';
  16. echo 'padding-bottom: 4px;';
  17. echo 'background-color: grey;';
  18. echo 'color: black;';
  19. echo '}';
  20. echo "</style>";
  21. $db_hostname = "127.0.0.1";
  22. $db_username = "cgscompu_deana1";
  23. $db_password = "040497";
  24. $db_database = "cgscompu_deana1";
  25. $db_server = mysql_connect($db_hostname, $db_username, $db_password);
  26. if(!$db_server) {
  27.     die("Unable to connect to MySQL: " . mysql_error());
  28. }
  29. mysql_select_db($db_database, $db_server) or die("Unable to select database: " . mysql_error());
  30. if($_GET['order'] == 1){
  31. $query = "SELECT * FROM todo_list ORDER BY person_id ASC";
  32. }elseif($_GET['order'] == 2)
  33. {
  34. $query = "SELECT * FROM todo_list ORDER BY name ASC";
  35. }elseif($_GET['order'] == 3)
  36. {
  37. $query = "SELECT * FROM todo_list ORDER BY age ASC";
  38. }elseif($_GET['order'] == 4)
  39. {
  40. $query = "SELECT * FROM todo_list ORDER BY email_address ASC";
  41. }elseif($_GET['order'] == 5)
  42. {
  43. $query = "SELECT * FROM todo_list ORDER BY phone_number ASC";
  44. }elseif($_GET['order'] == 6)
  45. {
  46. $query = "SELECT * FROM todo_list ORDER BY postcode ASC";
  47. }else{
  48. $query = "SELECT * FROM todo_list";
  49. }
  50.  
  51. $result = mysql_query($query);
  52. if(!$result) die ("Database access failed: " . mysql_error());
  53. $rows = mysql_num_rows($result);
  54. echo "<table border=\"1\" id=\"table\">";
  55. echo "<tr>";
  56. echo "<th><a href=\"my_contacts.php?order=2\">Name</a></th>";
  57. echo "<th><a href=\"my_contacts.php?order=3\">Age</a></th>";
  58. echo "<th><a href=\"my_contacts.php?order=4\">Email Address</a></th>";
  59. echo "</tr>";
  60. for ($j = 0;$j < $rows; $j++) {
  61.     echo "<tr>";
  62.     echo "<td>" . mysql_result($result,$j,'complete') . "</td>";
  63.     echo "<td>" . mysql_result($result,$j,'title') . "</td>";
  64.     echo "<td>" . mysql_result($result,$j,'created_timestamp') . "</td>";
  65.     echo "</tr>";
  66. }
  67. echo "</table>";
  68. mysql_close($db_server);
  69. echo "</center>";
  70. */
  71. ?>
  72. <html>
  73. <head>
  74.     <title>To-Do List</title>
  75.     <style>
  76.         html {
  77.             font-family: sans-serif;
  78.         }
  79.         table {
  80.             border-collapse:collapse;
  81.             margin-bottom: 20px;
  82.         }
  83.         table, th, td {
  84.             border: 1px solid black;
  85.         }
  86.         th, td {
  87.             padding: 5px;
  88.         }
  89.         th {
  90.             background-color: green;
  91.             color: white;
  92.         }
  93.         td.done-column, td.delete-column {
  94.             text-align: center;
  95.         }
  96.         td.done-column a, td.delete-column a {
  97.             text-decoration: none;
  98.             font-weight: bold;
  99.         }
  100.         td.done-column a:hover, td.delete-column a:hover {
  101.             text-decoration: underline;
  102.         }
  103.         tr.item-complete, tr.item-complete a {
  104.             color: green;
  105.         }
  106.         tr.item-incomplete, tr.item-incomplete a {
  107.             color: red;
  108.         }
  109.     </style>
  110. </head>
  111. <body>
  112. <h2>Online To-Do List</h2>
  113. <table>
  114. <tr>
  115. <th>Done</th>
  116. <th>Title</th>
  117. <th>Created</th>
  118. <th></th>
  119. </tr>
  120. <?php
  121. $db_hostname = "127.0.0.1";
  122. $db_username = "cgscompu_deana1";
  123. $db_password = "040497";
  124. $db_database = "cgscompu_deana1";
  125. $db_server = mysql_connect($db_hostname, $db_username, $db_password);
  126. if(!$db_server) {
  127.     die("Unable to connect to MySQL: " . mysql_error());
  128. }
  129. mysql_select_db($db_database, $db_server) or die("Unable to select database: " . mysql_error());
  130. $result = mysql_query("SELECT * FROM todo_list");
  131. $rows = mysql_num_rows($result);
  132.  
  133. if(isset($_GET["done"])){
  134. mysql_query("UPDATE todo_list SET complete=" . $_GET["done"] . " WHERE todo_id=" . $_GET["todo_id"]);
  135. }
  136.  
  137. // Render table
  138.  
  139. for ($j = 0;$j < $rows; $j++) {
  140.     switch (mysql_result($result,$j,'complete'))
  141. {
  142. case 0:
  143.   echo '<tr class="item-incomplete">';
  144.   echo '<td class="done-column"><a href="ToDo.php?todo_id=' . mysql_result($result,$j,'todo_id') . '&done=1' . '">NO</a></td>';
  145.   echo '<td class="title-column">' . mysql_result($result,$j,'title') . '</td>';
  146.   echo '<td class="created-column">4 days ago</td>';
  147.   echo '<td class="delete-column"><a href="ToDo.php?delete_todo_id=' . mysql_result($result,$j,'todo_id') . '">[X]</a></td>';
  148.   break;
  149. case 1:
  150.   echo '<tr class="item-complete">';
  151.     echo '<td class="done-column"><a href="ToDo.php?todo_id=' . mysql_result($result,$j,'todo_id') . '&done=0' . '">YES</a></td>';
  152.       echo '<td class="title-column">' . mysql_result($result,$j,'title') . '</td>';
  153.         echo '<td class="created-column">4 days ago</td>';
  154.   echo '<td class="delete-column"><a href="ToDo.php?delete_todo_id=' . mysql_result($result,$j,'todo_id') . '">[X]</a></td>';
  155.   break;
  156. }
  157. //  echo <td class="done-column"><a href="ToDo.php?todo_id=1&done=1">NO</a></td>
  158. //  echo "<td>" . mysql_result($result,$j,'created_timestamp') . "</td>";
  159.     echo "</tr>";
  160. }
  161. /*
  162. echo '<tr class="item-complete">';
  163. echo '<td class="done-column"><a href="ToDo.php?todo_id=5&done=0">YES</a></td>';
  164. echo '<td class="title-column">Weekend soccer game</td>';
  165. echo '<td class="created-column">4 days ago</td>';
  166. echo '<td class="delete-column"><a href="ToDo.php?delete_todo_id=5">[X]</a></td>';
  167. echo '</tr>';
  168. */
  169. echo '</table>';
  170. ?>
  171. <form method="post" action="ToDo.php">
  172. New To-Do Item: <input type="text" name="todo-title" size=40/><input type="submit" value="Add" />
  173. </form>
  174. <hr />
  175. <p><strong>You do not need to implement anything below this line.</strong></p>
  176. <p>The Reset button will simply reset the database back to it's original state - this is because this sample program is shared (i.e. anyone can access it and modify it, and potentially mess it up) so the Reset will put it back to it's original state for your testing.</p>
  177. <form method="post" action="ToDo.php">
  178. <input type="submit" name="reset" value="Reset" />
  179. </form>
  180. </body>
  181. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement