Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load search upon hitting back arrow #45

Open
rprusacki1 opened this issue Sep 4, 2023 · 5 comments
Open

Load search upon hitting back arrow #45

rprusacki1 opened this issue Sep 4, 2023 · 5 comments
Assignees

Comments

@rprusacki1
Copy link
Contributor

rprusacki1 commented Sep 4, 2023

  • add "back" button once an animal is clicked to get back to the search
@rprusacki1
Copy link
Contributor Author

-Add back button that loads search results

@rprusacki1 rprusacki1 changed the title Make “add, update, delete” buttons work on animal page​ Make “add" button work on animal page​ Sep 6, 2023
@jtrbg
Copy link
Contributor

jtrbg commented Sep 9, 2023

Is this for the add button or the back button?
Do you mean for the back button to temporarily save the previous search, or just for it to pop-up with results?

@rprusacki1
Copy link
Contributor Author

Back button to save previous search so it loads results when you hit the back arrow instead of being blank

  • add "add species" option

@jtrbg
Copy link
Contributor

jtrbg commented Sep 12, 2023

Submit inputs through POST to a file called addAnimal.php

In addAnimal.php, check that the post values are set, then prepare the queries:

// Sets the queries used in the update
$checkDup = $connection->prepare("SELECT id FROM animals WHERE id=?");
$checkDupSPX = $connection->prepare("SELECT id FROM species WHERE id=?");
$addAni = $connection->prepare("INSERT INTO animals (id,section,sex,birth_date,acquisition_date,species_id,'name') VALUES (?,?,?,?,?,?,?)");
$addSpx = $connection->prepare("INSERT INTO species (id,form_id) VALUES (?,?,?,?,?,?,?)");

Then check if there already exists a species of that name($NEW_SPX can be replaced with your POST value):

$checkDupSPX->bind_param("s", strip_tags($NEW_SPX, '<br>'));
$checkDupSPX->execute();
$checkDupSPX->bind_result($idSPX);
$checkDupSPX->fetch();
$checkDupSPX->close();

If there is no existing species with that name, create a new one. Then add the animal to the DB:

if (is_null($idSPX)) { // This is a new question
    $addSpx->bind_param("ss", strip_tags($NEW_SPX), strip_tags($NEW_FID));
    $addSpx->execute();
}
$addSpx->close();

$addAni->bind_param("sssssss", strip_tags($NEW_BD, '<br>'), $NEW_SEC, $NEW_SEX, strip_tags($NEW_SPX, '<br>'), strip_tags($NEW_AD, '<br>'), strip_tags($NEW_HOU, '<br>'));
$addAni->execute();
$addAni->close();

@rprusacki1 rprusacki1 changed the title Make “add" button work on animal page​ Load search upon hitting back arrow Sep 12, 2023
@jtrbg
Copy link
Contributor

jtrbg commented Sep 12, 2023

For the back button, we need to just save the search in the session, then go back and fetch that search.
In the PHP section of search.php:

<script>
          let cachedFilterData = JSON.parse(sessionStorage.getItem("searchFilter"));
          if (cachedFilterData.length > 0) {
            $.ajax({
              type: 'POST',
              data: 'search='cachedFilterData''
              
            });
            sessionStorage.removeItem("searchFilter");
          }
        </script>
        <?php
        if (isset($_POST['search'])) {
          $search = $_POST['search'];
          ?>
          <script>
            sessionStorage.setItem("searchFilter", JSON.stringify($_POST['search']));
          </script>
          <?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants