Filling a Drop down box with an ID in the table?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alexlindley
Forum Newbie
Posts: 1
Joined: Sun Mar 13, 2005 9:40 am

Filling a Drop down box with an ID in the table?

Post by alexlindley »

Hi,

Im having a really frustrating problem! I have to admit im new to PHP and dont know exactly what im doing yet but i was wondering if someone could help me with the following problem.

I am trying to build a site as a project which is similar to imdb.com with a loggen in user to be able to review and browse movies in a mysql database. However im only really at the begining stages of all this and i am currently having a problem with the page i am using to input data into the database tables with. The page has all the usual, MovieID, MovieName, Runtime ect.. but also two enum rows, Genre and Certificate. I am having trouble populating the drop down box containing these values, currently it just loads up empty.
This is the code i am using;

Code: Select all

<tr>
    <td bgcolor="#FFFFFF">Movie Genre</td>
    <td bgcolor="#FFFFFF">
      <select name="movie_genre">
      <option value="" selected>Select a genre for the film...</option>
      
<?php
  $sql = "SELECT (possible ID??), Genre " .
         "FROM Movie ";
  $result = mysql_query($sql)
    or die("<font color=\"#FF0000\">Query Error</font>" .
           mysql_error());
  while ($row = mysql_fetch_array($result)) {
    if ($row['Genre'] == $movie_type) {
      $selected = " selected";
    } else {
      $selected = "";
    }
    echo '<option value="' . $row['(PossibleID??)'] . '"' . 
         $selected.'>' . $row['Genre'] . '</option>' . 
         "\r\n";
  }
?>
      </select>
    </td>
  </tr>
As you can see it should be selecting an ID but of course there isnt one in my table for the genre as the ID is given to the movie ID. So is there a more simple way of achieving this without the ID? Or do i need to make seperate tables for the Genre and Certificate Rows?

I would be very greatful for any help you could provide,
Regards,
Alex


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's best to have seperate tables for genre and certificate. As the rating may vary depending on release, and a lot of films these days have multiple genre's.

The only other way is to use a SET for genre at least. In order to find the possible values, of a SET/ENUM is through describing the table's structure, finding those types and extracting the information. I find it a lot easier to have a seperate table for these kinds of things though. With a third table that links the two parts together via ID's
Post Reply