Generos Link($_GET)

Asked

Viewed 129 times

0

I’m working on a project to learn about PHP, and at the moment I stopped to make a link 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 the $dbCheck[0]['genero']; is returning me the Genre that has registered to this video.

As soon as the value is returned to the screen, a link is generated in it so that when clicking bring all videos of the same genre

I’m at the beginning of learning, so I couldn’t do many tests.

  • I didn’t get it right ... the problem is that the link is mounted without id? avoid using arrobas

  • @rray genero are values returned from the database, for user they will be links, and when clicking it filters all records with the same gender. Click Action, return all action on index;

  • the link is mounted correctly? $dbCheck[0]['genero'] pq is indexed to zero?

  • My dear your question made me find the mistake! Thank you

1 answer

1

I took advantage of the links I generated on the homepage, which used GET to filter the content of the bank:

$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, taking advantage of the SELECT data by Function Dbread:

$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, for this reason I use the... My idea is to stop using this medium and go back to the root of the code and so, who knows have a better understanding of the functionalities.

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

  • 1

    Put the code that has changed. What it was and explains why it has changed. Take advantage that you are learning and see these tips

Browser other questions tagged

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