0
have 2 tables , the articles table and the table categorie_article in the database, what I want is the following, that appear all the names of registered categories (ex CATEGORIA1, categoria2, etc) and when clicking the category goes to a category.php file where it displays all the posts of the category I clicked, regardless of the category clicked goes in this document, could help me please look below the code I made only appears the name and ID of the category, based on it I complete the code and the category.php by kindness ? Cod below =
<?php
$result_categoria = "SELECT * FROM artigos WHERE sts_situacoe_id=1 ORDER BY id DESC LIMIT 6";
$resultado_categoria = mysqli_query($conn, $result_categoria);
?>
<div class="p-3">
<h4>Categorias</h4>
<ol class="list-unstyled" data-categoria="comida">>
<?php
while($row_categoria = mysqli_fetch_assoc($resultado_categoria)){
echo "<li><a href='".pg."/artigo/".$row_categoria['id']."'>".$row_categoria['nome']."</a></li>";
}
?>
</ol>
</div>
Thanks Junior for the help, but I tried here and it’s giving error, there is no value appearing,I want to appear category names , I tried to see but I could not enter the error, I did some tests and it did not work, .. can you see for me ? and yes the table articles have a key rule article_categoria_id to get the value of the table category.
– Leticia
Could give a print_r($resultado_category) so I can help you better.
– Junior Silva
edited there, I accidentally added the >.. Oops! , but it looks like nothing came out. I changed my question above, because I was wrong > haha sorry
– Leticia
<?php $result_categoria = "SELECT * FROM articles where sts_situacoe_id=1 ORDER BY id DESC LIMIT 6"; $resultado_categoria = mysqli_query($Conn, $result_categoria); ?>
– Leticia
<div class="p-3"> <H4>Categories</H4> <ol class="list-unstyled"> <?php while($row_categoria = mysqli_fetch_assoc($resultado_categoria)){ echo "<li><a href='".pg."/article/category.php? category=". $row_category['id']." '>". $row_category['name']." </a></li>";
– Leticia
} ? > </ol> </div>
– Leticia
Leticia, put this print_r in the post editing it.
– Junior Silva
?php $result_category = "SELECT * FROM articles WHERE sts_situacoe_id=1 ORDER BY id DESC LIMIT 6"; $resultado_category = mysqli_query($Conn, $result_category); ? > <div class="p-3"> <H4>Categories</H4> <ol class="list-unstyled"> <? php while($row_categoria = mysqli_fetch_assoc($resultado_categoria)){ echo "<li><a href='".pg."/article/category.php? category=". $row_categoria['id']." '>". $row_categoria['name']." </a></li>"; } ? > </ol> </div>
– Leticia
Ready Cod complete above
– Leticia
I edited my reply with the corrections I thought necessary.
– Junior Silva
Too bad we can not chat by chat Junior, now appeared the categories uhuhu, but is giving page not found now in the category.php <- as if there was no Uch! If I learn this I can do and finish the rest of the project, that’s pretty much all that’s missing oh Gosh! I’ll have to leave now, tomorrow I’ll continue, but if you know the reason and can warn
– Leticia
If the page is not found, you need to check the path to it in href, enter your code in <li> and see what it shows in href of them, analyze to see where the error is, if you prefer, copy the path and paste in the url in the browser and see if the page opens.
– Junior Silva
Good morning Junior, I managed in the address url on the page I took the $ before the pg and the category=, directs however it is not displaying the posts, within the query in the category.php I put for normal display, but nothing. ah sorry work, if you want to give up helping me all right I understand, worse than after learning if you say "puutz so simple" had things that I delayed after I learned it was super easy... this one I’m suffering
– Leticia
check if your query is bringing results, check what value appears in the GET variable, you are handling possible errors in your query? if not, print your query string, copy and in phpmyadmin go to the table and make an SQL with your query and see what the phpmyadmin panel gives you as an answer.
– Junior Silva