Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Problem with selecting by category

    Hi there,

    I have the following problem : I have a script wich catalogues my movies.
    I want to be able to view them by genre but also to view them all in one list.
    The problem I'm having is : It always returns all the movies.

    The form :
    PHP Code:
        <form action="verwerk.php?action=view" method="post">
        Genre: <br />
            <select name="genre">
                <option value="alles">Alles</option>
                <?php 
                
    if ($result=$link->query($query)) {
                  for (
    $i=0$i $result->num_rows$i++) {
                    
    $rij$result->fetch_assoc();
                    print(
    "<option value=\"{$rij['id']}\">{$rij['genre']}</option>\n");
                  }
                  
    $result->close();
                }
                
    ?>
            </select><br />
            <input type="submit" class="button" value="Bekijk" />
        </form>

    And the PHP



    PHP Code:
    case view:
            if ($_POST['genre']="alles") {
            $query = "SELECT *
                      FROM divx INNER JOIN genres ON genreid=genres.id";
            
            }
            else {
            $query = "SELECT *
                      FROM divx INNER JOIN genres ON genreid=genres.id
                      WHERE \"{$_POST['genre']}\"=genreid"; 
            }
            ?>
            <table class="result">
                <tr>
                    <td class="top">Titel</td>
                    <td class="top">Genre</td>
                </tr>
            <?php
            
    if ($result=$link->query($query)) {
              for (
    $i=0$i $result->num_rows$i++) {
                
    $rij$result->fetch_assoc();
                print(
    "<tr>\n");
                print(
    "<td class=\"cell1\">{$rij['titel']}</td>\n");
                print(
    "<td class=\"cell2\">{$rij['genre']}</td>\n");
                print(
    "</tr>\n");
            
              }
              
    $result->close();
            } 
            
    $link->close() or die("Kan link met $dbserver niet sluiten.");
            
    ?>
            </table>
            <a href="film.php">Terug</a>
    <?php
    break;
    Has anyone got any idea ?

  • #2
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Try:

    PHP Code:
            $query "SELECT *
                      FROM divx INNER JOIN genres ON genreid=genres.id
                      WHERE genreid = '"
    .mysql_real_escape_string($_POST['genre'])."'"
            } 
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by meth View Post
    Try:

    PHP Code:
            $query "SELECT *
                      FROM divx INNER JOIN genres ON genreid=genres.id
                      WHERE genreid = '"
    .mysql_real_escape_string($_POST['genre'])."'"
            } 

    Thanks, but it yields the same result. I'm thinking something is going wrong in the if/else function. I can't seem to find the problem though.

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    ($_POST['genre']="alles")
    This line is NOT checking the value of $_POST['genre']. To do so, use:
    Code:
    ($_POST['genre'] == "alles")
    == is a comparison operator, = is an assignment operator
    John

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PappaJohn View Post
    ($_POST['genre']="alles")
    This line is NOT checking the value of $_POST['genre']. To do so, use:
    Code:
    ($_POST['genre'] == "alles")
    == is a comparison operator, = is an assignment operator

    gee, do I feel stupid =D
    It works now, thanks alot !


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •