SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help me on this mysql

    --
    -- Table structure for table `column_ads`
    --

    CREATE TABLE IF NOT EXISTS `column_ads` (
    `id` int(5) NOT NULL AUTO_INCREMENT,
    `column_id_1` int(10) NOT NULL,
    `column_id_2` int(10) NOT NULL,
    `column_id_3` int(11) NOT NULL,
    `column_id_4` int(11) NOT NULL,
    `column_id_5` int(11) NOT NULL,
    `column_id_6` int(11) NOT NULL,
    `column_id_7` int(11) NOT NULL,
    `column_id_8` int(11) NOT NULL,
    `column_id_9` int(11) NOT NULL,
    `page_id` int(5) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

    --
    -- Dumping data for table `column_ads`
    --

    INSERT INTO `column_ads` (`id`, `column_id_1`, `column_id_2`, `column_id_3`, `column_id_4`, `column_id_5`, `column_id_6`, `column_id_7`, `column_id_8`, `column_id_9`, `page_id`) VALUES
    (1, 6, 2, 3, 2, 3, 3, 3, 3, 3, 1),
    (8, 2, 2, 3, 2, 3, 3, 3, 3, 3, 34);

    --
    -- Table structure for table `advertisement`
    --

    CREATE TABLE IF NOT EXISTS `advertisement` (
    `ad_id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(60) NOT NULL,
    `script` text NOT NULL,
    `created_on` varchar(30) NOT NULL,
    PRIMARY KEY (`ad_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

    --
    -- Dumping data for table `advertisement`
    --

    INSERT INTO `advertisement` (`ad_id`, `title`, `script`, `created_on`) VALUES
    (3, 'gghf', '<html><title>hello</title></html>', 'March 22, 2010, 6:56 am'),
    (2, 'sofent', '<script typefghf="text/javascript>\r\nhi</script>', 'March 22, 2010, 6:51 am'),
    (5, 'vcbcvb', '<html><title>hello</title></html>', 'March 23, 2010, 8:37 am'),
    (6, 'fdg', '<html><title>hello</title></html>', 'March 23, 2010, 9:47 am');

    Actually
    i need to extract the data from script column from advertisement table..

    notes: column_id_1,....column_id_9 from column_ads table holds advertisement table ad_id data.
    i need to extract the script from advertisement table by column_id_1---column_id_9 where page_id = (example:1)

    output like:

    column_id_1-->2 means i want to extract <script typefghf="text/javascript>\r\nhi</script> bec ad_id is 2

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If you normalize your first table to this:
    Code MySQL:
    CREATE TABLE IF NOT EXISTS `column_ads` (
    `id` int(5) NOT NULL AUTO_INCREMENT,
    `column_id` int(5) NOT NULL,
    `ad_id` int(11) NOT NULL,
    `page_id` int(5) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
    Then joining it with the second table becomes much easier.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by guido2004 View Post
    If you normalize your first table ...
    dear nsatheesh87 ... see? i'm not the only one who suggests this

    and i already showed you how to write the series of joins you will need
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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