Generos Link ($ _ GET)

0

I'm working on a project to learn about PHP, and at the moment I've taken a link to access the bank and bring everything that has its same value or id ...

<?php
    $generos  = explode(',', $post['genero']);

    foreach ($generos as $categ){
        $dbCheck = DBRead('generos', "WHERE id ='". $categ . "'");
?>

<a href="index.php?catalogo=<?php @$categ['id']; ?>"><?php echo $dbCheck[0]['genero']; ?></a>
<?php
        if (isset($_GET['catalogo'])) {
            $catalogo = $_GET['catalogo'];
            $dadoCat = DBRead('posts', "WHERE status = 1 AND genero = '".$categ."' ORDER BY data DESC");
        }
    }
?>

In this case, $dbCheck[0]['genero']; is returning the Genre that has been added to this video.

Once the value is returned to the screen, a link is generated on it so that when clicking it brings all the videos of this same genre

I'm at the beginning of learning, so I was not able to do many tests.

    
asked by anonymous 25.08.2015 / 23:03

1 answer

1

I used the links I generated on the home page, which used GET to filter the contents of the database:

$cWhereTipo = "";
$cWhereGenero = "";
//Verifica se tem tipo vindo do cliente:
$aGet = array();
//Se for setado TIPO na url, gera 2 variais $cWhereTipo
//para instrução SQL e $aGet[] para tipo=filme ou serie ou animes
if (isset($_GET['tipo'])){
    $cWhereTipo = " AND tipo = '" . ucfirst($_GET['tipo']) . "'";
    $aGet[] = 'tipo=' . ucfirst($_GET['tipo']);
}

I added another block to filter the new GET:

if (isset($_GET['genero'])){
   $cWhereGenero = " AND genero LIKE '%" . ucfirst($_GET['genero']) . "%'";
   $aGet[] = 'genero=' . ucfirst($_GET['genero']);
} 

The Links were as follows, making use of the SELECT given by the DBRead function:

$post = DBRead('posts', "WHERE id = '{$id}' LIMIT 1");
$generos = DBRead('generos', "ORDER BY genero DESC");
<?php
    $generos  = explode(',', $post['genero']);
    foreach ($generos as $categ){
        $dbCheck = DBRead('generos', "WHERE id ='". $categ . "'");
?>
<a href="index.php?genero=<?php echo @$categ['id']; ?>"><?php echo $dbCheck[0]['genero']; ?></a>
<?php } ?>

When I started this project I was watching some video lessons, so I use the functions ... My idea is to stop using this medium and go back to the root of the code and thus, who knows a better understanding about the features.

Next step is to include this same genre, now in the index, below each video.

    
26.08.2015 / 00:30