So, I'm still a little new to PHP, MySQL and Javascript, but I was working on a project, so I'm learning fast. However, I feel like I am mixing too much HTML and PHP on my php pages. At first I thought it was standard practice, but someone from SO told me how you should not mix these two, and I started looking at my code.
For example, when loading the views page, I have a loop that looks something like this (compressed version):
<?php while ($row = mysql_fetch_assoc($submissionQuery)) { $submissionID = $row['id']; ?> <div class="submission" id="submission<?php echo $submissionID; ?>"> <h3><?php echo $row['title']; ?></h3> </div> <?php } ?>
The reason I’m not just embedding the whole block in PHP is because not only h3 is there, but I don’t want to use mass echo expressions.
In my opinion, it looks awful, and I would like to know the best way to do this. I believe that I could store all the materials in an array and then scroll through them later, but I see a few drawbacks:
1) Without the need to store values in an array. Just going to remember them right after.
2) If there are many messages, there may not be enough memory to store them.
3) More code required.
4) Still have to iterate over the array later, in which case I'm still mixing PHP and HTML (only to a lesser extent)
I dont know. I just need some advice to better deal with this, because I don’t want to do something wrong, and then I will have to reorganize everything later when something breaks or becomes too complicated.