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
https://forums.phpfreaks.com/topic/260105-db-set-up/
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
https://forums.phpfreaks.com/topic/260105-db-set-up/#findComment-1333124
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
https://forums.phpfreaks.com/topic/260105-db-set-up/#findComment-1333134
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.