I'm trying, in a MVC-like arvchitecture (every page has an url"index.php?action=nameofthepage"), to display a personnal page corresponding to every item already displayed in previous page through a while loop(1):
view page 1:
while ($data=$eleves->fetch()) {?>
<div class="enseignant">
<a href="index.php?action=portraitDanciensIndividuel&id=<?=$data['id']?>"> // this doesn't work
<img src="<?php echo $data['photo']?>" alt="" class="photoEnseignant">
<h2 style="margin-left:auto;margin-right:auto;"><?= $data['prenom'] .' '. $data['nom']?></h2>
</a>
</div>
<?php } ?>
view page 2:
<?php
$data=$stmt->fetch() ?>
<img src="<?= $data['photo']?>" alt=""class="AfficherEleveIndividuelPhoto">
<h3 ><?=$data['prenom'] .' '. $data['nom']?></h3>
<p class="seCultiverTxt">
<?=nl2br($data['description'])?>
</p>
model page 2:
<?php
//PDO etc.
$stmt = $bdd->prepare('SELECT * FROM eleves WHERE id=?');
$stmt->execute(array($_GET['id']));
controller page 2
function portraitIndividuel() {
require ('dbConnect.php');
require ('models/PortraitsDanciensIndividual.php');
require ('portraitDancienIndividuelV.php');
}
router page 2
if ($_GET['action'] == 'portraitDanciensIndividuel') {
portraitIndividuel();
}
here's my question: i'm wondering how to go on another page using the action parameter and also including the id parameter ?
I'm quite new in php!
I already tried many different things
Any clue is welcome
My Answer:
), to pass several parameters in the URL. For example, if I have a page that displays a user's profile, I want to pass the user's ID and username in the URL like this:
/profile.php?id=123&username=johndoe
To access these parameters in PHP, you can use the $_GET superglobal array like this:
php
$id = $_GET['id'];
$username = $_GET['username'];
You can then use these parameters to fetch the user's information from a database or perform any other necessary actions. Just make sure to properly sanitize and validate the input to prevent any security vulnerabilities.
Rate this post
4 of 5 based on 9072 votesComments