I have been working on a project recently. I have a DB where I have saved various elements such as id, title, imgUrl, intro and title. I want to retrieve those data from the MySQL database to a PHP array as follows:
<?php
$slides = array(
array(
'id' => 1,
'title' => '',
'intro' => '',
'imgUrl' => '',
'content' => ''
),
array(
'id' => 2,
'title' => '',
'intro' => '',
'imgUrl' => '',
'content' => ''
),
?>
I will use this code to display it in another PHP/HTML file that I have already created as follows:
<?php foreach ($slides as $slide): ?>
<div class="swiper-slide" id="slider<?= $slide['id']; ?>">
<div class="card">
<div class="card_image">
<img src="<?= $slide['imgUrl']; ?>">
</div>
<div class="card_info">
<h3 class="card_title">
<?= $slide['title']; ?>
</h3>
<p>
<?= $slide['intro']; ?>
</p>
<button data-modal-target="#modal<?= $slide['id']; ?>" class="card_btn">
<h4>Learn More</h4>
</button>
</div>
</div>
</div>
<?php endforeach; ?>
I am still new to PHP array and database but as per my project, I have to use those and I was wondering if there is any way for me to retrieve my data element from MySQL and display it in the PHP array I have created above.