0
I’m creating a platform where I need to change elements of the site by a control panel, and for example, it would be something very bad way insert into BD and pull via PHP?
Let’s say I have a menu with the following options in my menu:
1. Articles
2. Matters
3. Partners
4. Promotions
5. Contact
6. Send Your Text
Imagine that in the comic book is like this:
Id | titulo | status
1 | <li><a href="#">Artigos</a></li> | 1
2 | <li><a href="#">Matérias</a></li> | 1
3 | <li><a href="#">Parceiros</a></li> | 1
4 | <li><a href="#">Promoções</a></li> | 1
5 | <li><a href="#">Contato</a></li> | 1
6 | <li><a href="#">Envie seu Texto</a></li> | 1
Let’s say:
status 0 = oculto
status 1 = ativo
Just to illustrate, the code, for example, would be something like this:
<ul class="menu">
<?php
include('includes/conn.php');
$query = 'SELECT titulo FROM '.$tabela.' WHERE status = 1';
if($stmt = $mysqli->prepare($query)){
$stmt->execute();
$stmt->bind_result($titulo);
while($stmt->fetch()){
?>
<?php echo $titulo; ?>
<!-- COMNENT :: SAÍDA --
<li><a href="#">titulo</a></li>
<li><a href="#">Artigos</a></li>
<li><a href="#">Matérias</a></li>
<li><a href="#">Parceiros</a></li>
<li><a href="#">Promoções</a></li>
<li><a href="#">Contato</a></li>
<li><a href="#">Envie seu Texto</a></li> <<< ESTE NÃO APARECE
-->
<?php
}
$stmt->close();
}
$mysqli->close();
?>
</ul>
Well, I could just change that in the database and put, for example, the option 6 with status of "occult" (status=0) and hide this option from the menu when needed.
Basically, this consists of a platform with dynamic elements if used widely in design or is bad practice?
I think the good practice part, goes from person to person... I personally do like you and I think a lot of projects are programmed this way. What other way to complete this operation?
– White
Thanks for the feedback. The other way would be to simply leave these convenience objects aside in PHP and try some javascrpit solution.
– Alex Lupóz
If you need to create a screen that manages the options, will it force your user to write all the HTML code of the option? In my view, it makes much more sense for you to just store the information in the bank and build the HTML only when displaying.
– Woss
Bad practice is not, wordpress does this and is one of the most used frameworks today. From a researcher how he does it, how he keeps it in the comic book, will give you an idea of the best way to save this data.
– Costamilam
@Guilhermecostamilam do not think Wordpress is a Frameworks necessarily (you can even categorize as such), but also do not think it is a good example of how to do things, in fact I think it is an example of how not to (at least in most aspects of it).
– Guilherme Nascimento