2
Good! I am trying to call a PHP function at the click of a button. My solution so far:
<?php
$result = getResult($mysqli,"SELECT * from todos WHERE sender = '$username' AND status = '$value' AND journal = '$journal' ORDER BY expiration_date");
while($row = $result->fetch_array()){
$receiver = $row['receiver'];
$sender = $row['sender'];
$title = $row['title'];
$todo_text = $row['todo_text'];
$status = $row['status'];
$expiration_date = $row['expiration_date'];
$todo_id = $row['todo_id'];
?>
<div class="toDo"><b><?php echo $title; ?></b>
<ul class='date'>
<li><img src="icons/date.png" style="width:60px;"></li>
<li><?php echo "Due " . $expiration_date ?></li>
</ul>
<ul>
<li><?php echo $todo_text; ?></li>
<li><i><?php echo "assigned to ".$receiver." by ".$sender;?></i></li>
</ul>
<?php if($value == 'pending'){?>
<?php
if(isset($_POST['delete_x'])){
$todo_id = $_POST['todo_id'];
deleteToDo($mysqli,$todo_id,$journal);
exit();
}
if(isset($_POST['markAsDone_x'])){
$todo_id = $_POST['todo_id'];
markToDoAsDone($mysqli,$todo_id,$journal);
exit();
}
?>
<form method ="POST" action="">
<input type="hidden" name="todo_id" value="<?php echo $todo_id ?>"/>
<input type="image" name = "delete" src="icons/delete.png" style="width:20px"/>
<input type="image" name = "markAsDone" src="icons/done.png" style="width:20px"/>
</form>
<?php } ?>
</div>
<hr>
<?php
}
This works. I’m running a while loop, so this code is running several times. On my site, I have a page that lists different 'To Do’s', and each has a 'Delete' button and another 'Mark as Done'. However, when I click on one of these buttons, I have to update my page to give me the listing of To Do’s. For example: I want to delete the third To Do from the list. I click the 'Delete' button of the third To Do, but for some reason the page shows me the whole FIRST of the while cycle. If I refresh the page, I get the updated list without the same To Do. That is: the connection with the database is made successfully, but at the moment after clicking on the image should appear the updated listing of To Do’s, but simply appear to me the FIRST To Do do do while. The action is performed successfully, but the process is not 'Smooth' for the user! The page should be updated right after clicking the Delete button!
I still tried to use a header('Location:MINHA_PAGINA') before the exits, but without success.
Listing before performing the 'Delete' action':
What appears after clicking the 'Delete' icon of the third Whole: Any suggestions? Thank you :)
Enter the function code...
– MagicHat
Could you post the part where you effectively print the Whole ? Do you want to do this only with PHP itself ? The ideal would be to use Javascript and asynchronous requests to refresh the page.
– Lucas Queiroz Ribeiro
I added the code with the while cycle, as well as the layout of the elements of Todo. I also thought to use Javascript, but I don’t know how to adapt it..
– cortereal
A @cortereal tip, is missing the while lock key in the code posted.
– Oliveira
@Oliveira forgot that! I’ve updated :)
– cortereal
Well, you need to refresh after manually why you are deleting the record after you have already printed it, if you move the delete logic to start and then select will only print what you want. Then I try to post a more appropriate response.
– Lucas Queiroz Ribeiro