I have two questions if anyone can help me.
1- Is it okay to echo HTML elements in PHP or is it not preferred? I am asking this cz I read and heard that many people say it is bad practice to do so.
2- How can you break out of php while using a while loop and output all the elements? My code below only outputs the most recent element inserted in the database. However, if I echo all the HTML elements inside the php tags it works perfectly and I can output everything in the database. I have searched online but I could not find what I am looking for.
I have searched online and could not find what I was looking for so any help is appreciated.
<?php
$edu_details_query = "SELECT school_title, school_content FROM cv_education ";
$edu_stmt = mysqli_stmt_init($conn);
if (!$edu_stmt_prepare = mysqli_stmt_prepare($edu_stmt, $edu_details_query)) {
echo "QUERY FAILED" . mysqli_error($conn);
} else {
mysqli_stmt_execute($edu_stmt);
$edu_details_result = mysqli_stmt_get_result($edu_stmt);
while ($edu_details_rows = mysqli_fetch_assoc($edu_details_result)) {
$edu_details_row_school_title = $edu_details_rows['school_title'];
$edu_details_row_school_content = $edu_details_rows['school_content'];
} ?>
<div id='masters-edu'>
<h2><?php echo $edu_details_row_school_title; ?></h2>
<div id='edu-details'>
<?php echo $edu_details_row_school_content; ?>
</div>
</div>
<?php } ?>
NOTE: Please do not mind how I am querying the database, this is just for practice purposes. Do let me know if you have input though (my main reason for using prepared statements is because it has better security than mysqli)