How to take more than one bank category from the same table

Asked

Viewed 149 times

0

I’m developing a system for watching movies online and wanted to know how do I make films that are in 2 categories to be listed in both categories. I’m managing to list only on the first... someone could help?

I have the table of films in my system and there is a field called category varchar(100).

code:

<?php
require "conexao.php";
$cat = $_GET['cat'];
          $sql = "SELECT * FROM filme WHERE categoria = '$categoria' ORDER BY nome LIMIT 10";
            $qr = mysql_query($sql) or die(mysql_error());
            while($aux = mysql_fetch_array($qr)){
                $nome = $aux['nome'];
                $img = $aux['img'];
                $cate = $aux['categoria'];
                $sinopse = $aux['sinopse'];
                $cod = $aux['id'];
                print"
                        <div class=\"categoria\">
                            <ul class=\"col-md-3\">
                                <li><a id=\"popover\" data-trigger=\"hover\" data-toggle=\"popover\" title=\"$nome\" data-content=\"$sinopse\" href=\"watch.php?cod=$cod\"><img src=\"images/capa/$img\" title=\"$nome\" ></a></li>
                                <span class=\"resto2\">Hdtv</span>
                                <strong class=\"text text-center\">$nome</strong>
                            </ul>
                        </div>";
            }
?>

There’s the code I want you to take the category and in my index I have the href

<a href="algumacoisa.php?cat=acao">

and has more categories:

<a href="algumacoisa.php?cat=aventura">

what I wanted to know and how do I list a film of 2 categories as in the example filem has the category of action and adventure. how I make it to be shown in the 2 pages of action and adventure?

  • 1

    I can already say that you need to review the mapping of your database... Put your code, so we can help you.

  • The category field has separate values like this ação, aventeura, suspense ? all separated by comma?

  • yes I inserted a separated by comma did not work after inserting without comma and did not work either but it is separated yes

  • Dherik, had already sung the stone, you better normalize that column so there are no problems, if you are interested see that question or ONLY in temporary cases see that answer

  • No need to put resolvido just accept the answer (mark the green light), see another trick of the website here and How and why to accept an answer?

2 answers

1


Goodnight!

And if you try to use the SELECT LIKE

$sql = "SELECT * FROM filme WHERE categoria IS NOT NULL AND categoria like '%$cat%' ORDER BY nome LIMIT 10";

"I’m new here, I hope to learn more here too"

  • 1

    thank you face perfect function would never have thought of putting a filter there in sql. if Voce can explain me why the filter I Agradeco

  • As you have more than one category in the categories field, it is not known whether it is in the middle, at the beginning or at the end, so the LIKE with % at the beginning and at the end so it looks for all the items that contain the argument you are looking for.

  • now i intendi valeu even I thought that whenever I had a get my sql would have to be equal so I used p Where category = $cat for it to pass the value now intendi that I don’t always have to use that when I have 2 values that need to be passed I can use the way that Voce explained to me was even worth in thanks

  • guy I hadn’t noticed yesterday but got a bug I just noticed I only have a movie listed only as animation and this appearing in action could also help me solve I think he’s getting the action of the animation so this listing in the category of action could help me with that Gradeco?

  • Wow, I hadn’t thought about it, but so you can put your tabs inside the LIKE (I don’t know what they are) but kind of like '%/$Caf/%' so it only takes the word that’s inside the tab, LIKE considers space if it’s like '%$cat %'

  • I’m reading here and it’s asking me to use the explode but I’m putting and nothing I’m using it within the variable $sql ai dps like I was doing so explode('%$cat%'," ") but it’s not working

  • Almost getting face like I picked up the letter before the space because it is only getting after with the explosion I put so my like '%$cat %' Then he is taking only those that have name and then the space if I take the space of the end he gets all together then as that I make him take?

  • You tried without exploding ?! Because the explode it will generate an array

  • Voce talks using what you pass yes tried but n changed nothing

Show 4 more comments

0

You can create an array with categories and select them, for example:

SELECT * FROM filme WHERE categoria = IN ('acao','aventura')  ORDER BY nome LIMIT 10

As I don’t know how you are selecting more than one category let’s say you change yours href for something like:

<a href="algumacoisa.php?cat=acao+aventura">

So you just make one explode in php to return only the array you want "acao","aventura" or you can make some solution in javascript, for example the one I did in jquery.

alert($("a").attr('href').slice(20).split("+"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<a href="algumacoisa.php?cat=acao+aventura">Link</a>

You can already get a sense.

Browser other questions tagged

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