Change the retrieval logic to only get uncompleted tasks. Add a button below the tasks labelled "Show completed" that wi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Change the retrieval logic to only get uncompleted tasks. Add a button below the tasks labelled "Show completed" that wi

Post by answerhappygod »

Change The Retrieval Logic To Only Get Uncompleted Tasks Add A Button Below The Tasks Labelled Show Completed That Wi 1
Change The Retrieval Logic To Only Get Uncompleted Tasks Add A Button Below The Tasks Labelled Show Completed That Wi 1 (62.12 KiB) Viewed 25 times
Change The Retrieval Logic To Only Get Uncompleted Tasks Add A Button Below The Tasks Labelled Show Completed That Wi 2
Change The Retrieval Logic To Only Get Uncompleted Tasks Add A Button Below The Tasks Labelled Show Completed That Wi 2 (68.54 KiB) Viewed 25 times
Change the retrieval logic to only get uncompleted tasks. Add a button below the tasks labelled "Show completed" that will reload the page and display all tasks (completed and uncompleted). After this, the button should show “Hide completed" with appropriate functionality. For this feature, you'll need to use a hidden input form with data to indicate what your script should do when POSTed to. o o

o $con .check_err($var) : void • $stmt • $res o $id $new_title • $row • $title $created 1 <?php 2 3 require "secrets.php"; 4 $con = sqlsrv_connect("localhost", [ 5 5 "Database" => "example_db", 6 "UID" => DB_UID, 7 "PWD" => DB_PWD, 8 ]); 9 10 if ($con === false) { 11 echo "Failed to connect to db: " sqlsrv_errors()[0]["message"]; 12 exit(); 13 } 14 15- function check_err($var) 16 { 17 if ($var === false) { 18 echo "DB failure: " · sqlsrv_errors()[0]["message"]; 19 exit(); 20 } o o G 21 } 22 23 //adding new column to marks done or not 24 $stmt = sqlsrv_prepare($con, "ALTER TABLE todos ADD done boolean", [$id]); 25 check_err($stmt); 26 $res = sqlsrv_execute($stmt); 27 check_err($res); 28 29 if ($_SERVER['REQUEST_METHOD"] "POST") { if (isset($_POST["id"])) { 31 $id = $_POST["id"]; 32 $stmt = sqlsrv_prepared === 30

o o • $con • check_err($var) : void • $stmt o $res • $id $new_title $row • $title o $created o o o G 33 $con, 34 "UPDATE todos SET done = true WHERE id=?", 35 [$id] 36 ); 37 check_err($stmt); 38 $res = sqlsrv_execute($stmt); 39 check_err($res); 40 41 echo "<p>Todo item completed</p>"; 42 } else { 43 $new_title = $_POST["title"]; 44 $stmt = sqlsrv_prepare($con, "INSERT INTO todos (title) VALUES (?)", [ 45 $new_title, 46 ]); 47 check_err($stmt); 48 49 $res = sqlsrv_execute($stmt); 50 check_err($res); 51 52 echo "<p>Todo item addedd</p>"; 53 } 54 } 55 ?> > 56 57 <h2>Todo list items</h2> 580 <table><tbody> 59 <tr><th>Item</th><th>Added on</th><th>Complete</th></tr> 60 <?php 61 $stmt = sqlsrv_query($con, "SELECT id, title, created FROM todos"); 62 63 while ($row = sqlsrv_fetch_array($stmt)) { $ 64 $title = $row["title"]; = Line: 58

• $title o $created $id. 65 $created = $row["created"]->format("j"); 66 $id = $row["id"]; 67 echo "<tr>"; 68 echo "<td>" $title . "</td>"; 69 echo "<td>" . $created . "</td>"; 70 echo '<td><form method="post" action="todo.php"> 71 <input type="hidden" name="id" value="! 72 73 1"> 74 <button type="submit">Done</button> 75 </form></td>'; 76 echo "</tr>"; 77 } 78 79 sqlsrv_close($con); 80 ?> 81 </tbody></table> 82 <br/><br/> 83 84 <form method="post" action="todo.php"> 85 <input type="text" name="title" placeholder="Todo item"> 86 <button type="submit">Submit</button> 87 </form>
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply