Skip navigation links

MySQL Forums :: PHP :: Relate, join, add row to table or what?


Advanced Search

Relate, join, add row to table or what?
Posted by: Brian Adams ()
Date: September 28, 2013 02:38PM

I'm trying to make a simple recipe program. I'm new and starting with crude functionality. The index.php has the following links and options:

I've a table with 2 rows and 5 columns. Top row, first column says "cookbook names," second column is "add cookbook." Second row is a repeat region, first column lists the cookbook names, 2nd column has a link to "view chapters", 3rd column is change cookbook name and last column deletes cookbook and all chapters/recipes within.

The goal is to list cookbooks like:

Brians cookbook
Mary's cookbook
Our cookbook
...etc. When I click on view chapter next to a cookbook, I want to list chapters associated with the cookbook. e.g. Brian's cookbook has the folowing chapters within:

Sauces
Pasta dishes
Sea food
pork
...etc. Then click on a chapter, say sauces, and that would display a list of sauces, like mornay, bechemel, tomato, and finally, clicking on mornay sauce pulls up the recipe.

Think of it this way. I open a real, hard cover/paper cookbook, the index lists chapters, and when I go to a chapter, I see recipes.

MAN I hate typing!

How do I make it so that if I create a new cookbook, I can create chapters that will be in that cookbook and no others? Some kind of relation, a join command?


-- phpMyAdmin SQL Dump
-- version 3.3.5
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Sep 29, 2013 at 03:25 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.26

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `Gourmet_Entertainment`
--

-- --------------------------------------------------------

--
-- Table structure for table `chapter`
--

CREATE TABLE IF NOT EXISTS `chapter` (
`chapter_id` int(11) NOT NULL AUTO_INCREMENT,
`Chapter_Name` varchar(100) NOT NULL,
PRIMARY KEY (`chapter_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

--
-- Dumping data for table `chapter`
--

INSERT INTO `chapter` (`chapter_id`, `Chapter_Name`) VALUES
(1, 'Pasta'),
(2, 'Sauces'),
(4, 'Soups'),
(5, 'booze');

-- --------------------------------------------------------

--
-- Table structure for table `cookbook`
--

CREATE TABLE IF NOT EXISTS `cookbook` (
`cookbook_id` int(11) NOT NULL AUTO_INCREMENT,
`cookbook_name` varchar(100) NOT NULL,
PRIMARY KEY (`cookbook_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=21 ;

--
-- Dumping data for table `cookbook`
--

INSERT INTO `cookbook` (`cookbook_id`, `cookbook_name`) VALUES
(13, 'Brian''s Cookbook'),
(18, 'Mary''s'),
(20, '');

-- --------------------------------------------------------

--
-- Table structure for table `menu`
--

CREATE TABLE IF NOT EXISTS `menu` (
`menu_id` int(11) NOT NULL AUTO_INCREMENT,
`recipe_id` int(11) DEFAULT '0',
`name` varchar(100) DEFAULT NULL,
`prep_date` date DEFAULT NULL,
`cook_date` date DEFAULT NULL,
PRIMARY KEY (`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `menu`
--


-- --------------------------------------------------------

--
-- Table structure for table `recipe`
--

CREATE TABLE IF NOT EXISTS `recipe` (
`recipe_id` int(11) NOT NULL AUTO_INCREMENT,
`cookbook_id` int(11) DEFAULT '0',
`chapter` int(11) DEFAULT '0',
`page` int(11) DEFAULT '0',
`recipe_name` varchar(100) DEFAULT NULL,
`recipe` text,
PRIMARY KEY (`recipe_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dumping data for table `recipe`
--

INSERT INTO `recipe` (`recipe_id`, `cookbook_id`, `chapter`, `page`, `recipe_name`, `recipe`) VALUES
(1, 2, 2, 0, 'Drunken shrimp', 'cook with scotch'),
(2, 2, 2, 0, 'Alfredo Sauce', 'Lots of cream.');

-- --------------------------------------------------------

--
-- Table structure for table `recipe_incredents`
--

CREATE TABLE IF NOT EXISTS `recipe_incredents` (
`recipe_incredents_id` int(11) NOT NULL AUTO_INCREMENT,
`recipe_id` int(11) DEFAULT '0',
`incredents_id` int(11) DEFAULT '0',
`name` varchar(100) DEFAULT NULL,
`quantity` float DEFAULT '0',
`measurements` varchar(20) NOT NULL,
PRIMARY KEY (`recipe_incredents_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `recipe_incredents`
--

Options: ReplyQuote


Subject Written By Posted
Relate, join, add row to table or what? Brian Adams 09/28/2013 02:38PM
Re: Relate, join, add row to table or what? Rick James 09/30/2013 07:29PM
Re: Relate, join, add row to table or what? Brian Adams 10/01/2013 02:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.