Jump to content

DB SET UP


ecabrera

Recommended Posts

how does this work

 

i would get all the videos and list them in categorys

for example theres is

 

Comedy    cat=1

Horror      cat=2

Romance  cat=3

Drama      cat=4

Kids        cat=5

Action      cat=6

Travel      cat=7

 

http://website.com/list.php?cat=6

 

then i would  chose a category and inside the cat there are videos with ids

 

http://website.com/watch.php?cat=11&video=13

 

how would i set this up in a database

 

Link to comment
Share on other sites

This should help get you started

 

CREATE TABLE IF NOT EXISTS `video_categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;

CREATE TABLE IF NOT EXISTS `videos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cat_id` int(11) NOT NULL,
  `video_title` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

 

Now in order to link the "cat_id" in the "videos" table to the primary "id" in the "video_categories" table, you will need to use a JOIN.

 

Or a less elegant way to do it is:

 

SELECT * FROM videos, video_categories WHERE videos.cat_id = video_categories.id;

Link to comment
Share on other sites

If you mean a list of categories, then it would be something similar to this:

 

$sql = "SELECT * FROM videos, video_categories WHERE videos.cat_id = video_categories.id";
$results = mysql_query($sql);

while($row = mysql_fetch_array($results)) {
echo '<a href="list.php?cat=' . $row['cat_id'] . '">' . $row['category'] . '</a>';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.