How to filter by categories in php?

Asked

Viewed 42 times

0

Good afternoon guys, I’m new in web programming and I’m making an online schedule where a student registers a test or work that will and then (through CRUD) the site shows the evidence and registered works. However, I’m having trouble making a category screen. In my database have the following fields: id_evaluacao, disciplina_avaliacao, materia_avaliacao, professor_avaliacao, categoria_avaliacao e nota_avaliacao. I would like to have a menu on the page categories.php and in the menu have the category fields: arts, matematica, Portuguese etc... and when the user clicks on some field, the site shows the proofs of the selected category.

  • the category would be the disciplina_avaliacao ?

  • Actually, no, because the user entering the discipline field in the register, the string would go with uppercase letters and scores. Then the categiria would be categorie_rating that in the case would be the same string of the discipline field, but with database formatting.

  • So in the case of a discipline called Programação, in the discipline Programação and categorie_rating as programacao, that would be it ?

  • This, as in the evaluation register the field "Discipline" is as select, once you select a discipline, so the category will have the name of the discipline.

1 answer

0


I’ll try to give you a starting point.

Send the category name using the method _GET, from there you can use the code below as a base.

Remembering, this will only take the name of the category and make the call of what is inside this field. As you have disciplina_avaliacao and materia_avaliacao, I have decided for one of the two, however, can make use of the field that is necessary.

<?php
//Primeiro deverá pegar o nome da categoria através do $_GET, aqui, irei definir que o GET já possui um valor fixo pra poder continuar.
$_GET['cat'] = "matematica";

$categoria = $_GET['cat'];

$query = "SELECT * FROM categoria WHERE disciplina_avaliacao = " . $categoria . ";

//Montar a estrutura desejada abaixo

?>

This is what you need?

I hope I’ve helped.

  • In this case, the categories menu is on the same page as the results. So I would like to get the information straight from the database. It is necessary to have _GET?

  • Would do it without a refresh on the page?

  • I think it would be easier with the refresh.

  • Right, so in theory, you’ll have the menu on the left, every time you click, if you send for example the link <a href="categorias.php?cat=matematica" title="Matemática" /> can take the value through the _GET, if you want to go via _POST will have to create a page for each category... With the _GET will create only one and use the same page for numerous categories. The menu, header or other information, put as include() on the page, it will save you A lot of work.

  • If I want to do a side menu in index.php and the menu has a ul like <a href="categories.php? cat=matematica" title="Mathematics" /> I can take the value by _GET and do a SELECT * FROM tb_evaluations WHERE cat_evaluacao='$category'?

  • Exactly, inside the page categorias.php You’re going to do this select, from there all the magic happens. If you are working with a server, let me know that I can try to help you online.

  • I get it, I’m doing each test in a <div class = "card">, after doing the select, how do I echo this div? I’m doing it on localhost anyway, but I appreciate your help. I am doing a course in Systems Development and probably this will be my TCC kkkkk, by miracle I found this forum super welcoming and with people who have patience (just like you), I believe I will have a lot of help in this forum, I thank the attention.

  • Come on, relax hahaha. Well, you will have to do the following, within each link pass the url categorias.php?cat=nomedacategoria, he will open the page categorias.php, inside this page, get the category name in get $categorias = $_GET['cat'], after you do select, mount the home page this category exists. P.S.: If the answer helped, can you go back to it and mark it as correct by favor? hahaha

  • I got kkkkk, helped me very expensive. Marco yes, you can leave. Valeuu!!

  • Anything, pick up my email and I’ll help you as you get out of here ([email protected])

  • Opa valeu Jakson!!

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.