Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $mysql = mysql_connect("localhost", "root", "");
- if(!$mysql) echo "Connection error.";
- $mysql = mysql_select_db("todo");
- if(!$mysql) echo "Error selecting database.";
- $categories = array(1 => "Ogolne", 2 => "NPC");
- function addTodo()
- {
- $query = "insert into todo values(null, $_GET[show], '$_POST[todo]' , 0);";
- mysql_query($query);
- }
- function completeTodo($todo_id)
- {
- $query = "update todo set completed='1' where todo_id='".$todo_id."';";
- $check = mysql_query($query);
- }
- function getTodo($category)
- {
- $query = "Select * from todo where completed='0' and category=".$category.";";
- $rows = mysql_query($query);
- echo "<ul>";
- while($row = mysql_fetch_assoc($rows))
- echo "<li>".$row['description']." <a href='?show=".$row['category']."&complete=".$row['todo_id']."'>Done</a></li>";
- echo "</ul>";
- }
- function getTodoCompleted($category)
- {
- $query = "Select * from todo where completed='1' and category=".$category.";";
- $rows = mysql_query($query);
- echo "<ul>";
- while($row = mysql_fetch_assoc($rows))
- echo "<li>".$row['description']."</li>";
- echo "</ul>";
- }
- foreach($categories as $id => $cat)
- echo "<span style='padding: 5px;'><a href='?show=".$id."'>".$cat."</a></span>";
- if(isset($_GET['complete']))
- completeTodo($_GET['complete']);
- if(isset($_GET['add_todo']))
- addTodo();
- if(isset($_GET['show']))
- getTodo($_GET['show']);
- echo '
- <form action="?'.$_SERVER['QUERY_STRING'].'&add_todo" method="post">
- <input type="text" name="todo"/><br>
- <input type="submit" value="Add"/>
- </form>
- ';
- if(isset($_GET['show']))
- getTodoCompleted($_GET['show']);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement