I have been coding in PHP for not very long and I have a site where we have people and their people are on a given database (MYsql). Each name is linked to other names using ids. Each person has their page and I would like that if I am on the page of a person and the name of another is displayed, clicking on it refreshes the page with the data of the second person. expl: Jean's page (with his surname, first name, Age, (Michel) father, (Mireille) Mother) and when I click on father, the same page is displayed to me but with Michel as the name.
thank you very much for your answer
I tried to have the father's name displayed in a text input in a form and retrieved it with "if(isset($get['lenomduformulaire']) and I tried with post too. But that didn't m displayed that the variable did not exist. I also tried to put it in a button tag and same as before it didn't work.
CodePudding user response:
What you're describing just sounds like a link. For example:
<a href="person.php?id=123">Mother</a>
Basically the data for the current page would (should) include identifiers for the linked objects. For example, if the current person's "mother" has an ID of 123
. You'd populate the link with that person's mother's ID:
<a href="person.php?id=<?= $current_person->mother_id ?>">Mother</a>
(Or however you structure your data and identify your records, this is just for illustration purposes.)
When clicking on that link, the user is directed to "the same page" but with the ID value of another person. person.php
always just uses whatever ID is provided to query the data and display the "person".
CodePudding user response:
before answering your question I highly encourage you to use a PHP framework, like codeigniter or Laravel, this is very convenient for PHP starters.
Now answering your question and taking the previous answer, given by @David I would say that you can do it like this:
<a href="person.php?id=<?php echo htmlspecialchars($current_person>mother_id, ENT_QUOTES); ?>">Mother</a>