Hello, I'm new to PHP and I came across a problem: How to pass a PHP variable ($ id) that is inside a "a" tag into a Modal?
Here is the code:
<?php
require '../SisCellCenter/autoloader.php';
use VisaoJR\Cellcenter\ClassPHP\Products;
$products = new Products();
?>
<div class="content">
<div class="new-arrivals-w3agile">
<div class="container">
<!-- <h2 class="tittle">Destaques</h2> -->
<?php
$featuredProducts = $products->viewFeatureds();
$rand_keys = array_rand($featuredProducts, sizeOf($featuredProducts)); //escolhe produtos em destaque aleatoriamente
$max=0;
if(sizeOf($featuredProducts)>9){$max = 9;} else{$max = sizeOf($featuredProducts);} //exibe no máximo 9 produtos em destaque
for ($i=0; $i < $max; $i++) {
?>
<div class="arrivals-grids">
<div class="col-md-3 arrival-grid simpleCart_shelfItem">
<div class="grid-arr">
<div class="grid-arrival">
<figure>
<a class="new-gri" id="featured" data-toggle="modal" data-target="#featuredModal" value="<?php $id = $i; ?>">
<div class="grid-img">
<?php echo '<img src="images/Produtos/'.$featuredProducts[$rand_keys[$i]]->image.'">'; ?>
</div>
<div class="grid-img">
<?php echo '<img src="images/Produtos/'.$featuredProducts[$rand_keys[$i]]->image.'">'; ?>
</div>
</a>
</figure>
</div>
<div class="ribben">
<p>NEW</p>
</div>
<div class="ribben1">
<p>SALE</p>
</div>
<div class="women">
<h6><center><?php echo $featuredProducts[$rand_keys[$i]]->name; ?></center></h6>
<span class="size"><?php echo $featuredProducts[$rand_keys[$i]]->brand; ?></span>
</div>
</div>
</div>
<!-- <div class="clearfix"></div> -->
</div>
<?php }?>
</div>
</div>
</div>
<!--content-->
<!--Modal produtos em destaque-->
<div class="modal fade" id="featuredModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content modal-info">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<div class="news-gr">
<div class="col-md-5 new-grid1">
<?php echo '<img src="images/Produtos/'.$featuredProducts[$id]->image.'" class="img-responsive" alt="">'; ?>
</div>
<div class="col-md-7 new-grid">
<h5><?php echo $featuredProducts[$id]->name; ?></h5>
<h6><?php echo $featuredProducts[$id]->brand; ?></h6>
<span><?php echo $featuredProducts[$id]->description; ?></span>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
From now on, I thank anyone who can help me!