Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorjay0316
    • CommentTimeApr 1st 2009 edited
     permalink
    Hoping someone might be able to help me with my problem. I have 3 tables.
    "dealers" Structure
    Dealer_ID, Name, Address , ect

    "dealers_visit" Structure
    ID, Date

    "dealers_visit_lookup" Structure
    ID, Dealer_ID, Date_ID

    The tables allow us to record multiple visit dates for each store. What we'd like to have is a list of all the stores with the visit dates on the same row as the stores and put them into Quarter1, Quarter2, Quarter3, Quarter4 columns.

    So, I'd like to get all of these into excel spreadsheet. As of right now I get results with a company's info listed multiple times for each visit that was made. Which becomes a problem as more and more visits are made. Is there a way to consolidate the company information and keep the visits?

    This is my select statement, but I don't know how to get this into an excel document the way I want it.
    SELECT *
    FROM dealers , dealers_visit_lookup , dealers_visit
    WHERE (dealers.Dealer_ID = dealers_visit_lookup.Dealer_ID )AND (dealers_visit_lookup.Date_ID =dealers_visit.ID ) ORDER BY `dealers`.`Name` DESC";

    So right now I'm getting a list like this:
    Dealer 1 | 3-12-08
    Dealer 2 | 2-20-09
    Dealer 2 | 3-02-09
    Dealer 2 | 3-05-09
    Dealer 3 | 3-01-09

    What I'd like to get is this, but in an excel spreadsheet:
    Dealer 1 | 3-12-08
    Dealer 2 | 2-20-09 | 3-02-09 | 3-05-09
    Dealer 3 | 3-01-09

    You can see the code for the excel spreadsheet that I'm using in my post over here: http://www.phpfreaks.com/forums/index.php/topic,245571.0.html
    I think the person responding was leaving out the spreadsheet element.
  1.  permalink
    Could you post the mysqldump for creating the database with the sample data? It would be a lot easier to work with something tangible.
    • CommentAuthorjay0316
    • CommentTimeApr 2nd 2009
     permalink
    No problem Kari. Thanks for your help. Here is the dump and the next post will have the select statement I'm using, and of course the excel file contents are listed on the phpfreaks link.

    Dump:
    -- phpMyAdmin SQL Dump
    -- version 2.10.3
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generation Time: Apr 02, 2009 at 01:14 PM
    -- Server version: 5.0.45
    -- PHP Version: 5.2.3

    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

    --
    -- Database: `test`
    --

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

    --
    -- Table structure for table `dealers`
    --

    CREATE TABLE `dealers` (
    `Dealer_ID` mediumint(11) unsigned zerofill NOT NULL auto_increment,
    `Dealer_Zip` varchar(255) character set latin1 default NULL,
    `Dealer_BusinessName` varchar(255) character set latin1 default NULL,
    `Dealer_Address1` varchar(255) character set latin1 default NULL,
    `Dealer_City` varchar(255) character set latin1 default NULL,
    `Dealer_State` varchar(255) character set latin1 default NULL,
    `Completed_By` varchar(255) character set latin1 default NULL,
    PRIMARY KEY (`Dealer_ID`),
    UNIQUE KEY `ID_2` (`Dealer_ID`),
    KEY `ID` (`Dealer_ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=ascii AUTO_INCREMENT=4 ;

    --
    -- Dumping data for table `dealers`
    --

    INSERT INTO `dealers` (`Dealer_ID`, `Dealer_Zip`, `Dealer_BusinessName`, `Dealer_Address1`, `Dealer_City`, `Dealer_State`, `Completed_By`) VALUES
    (00000000001, '44621', 'Dealer 1', '1st St', 'Dennison', 'OH', 'Mark'),
    (00000000002, '44621', 'Dealer 2', '2nd St', 'Dennison', 'OH', 'Jason'),
    (00000000003, '44621', 'Dealer 3', '3rd St', 'Dennison', 'OH', 'Jason');

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

    --
    -- Table structure for table `dealers_visit`
    --

    CREATE TABLE `dealers_visit` (
    `ID` mediumint(11) NOT NULL auto_increment,
    `Date` date NOT NULL,
    PRIMARY KEY (`ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

    --
    -- Dumping data for table `dealers_visit`
    --

    INSERT INTO `dealers_visit` (`ID`, `Date`) VALUES
    (1, '2009-03-12'),
    (2, '2009-03-02'),
    (3, '2009-02-20'),
    (4, '2009-03-01'),
    (5, '2009-03-05');

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

    --
    -- Table structure for table `dealers_visit_lookup`
    --

    CREATE TABLE `dealers_visit_lookup` (
    `ID` mediumint(11) NOT NULL auto_increment,
    `Dealer_ID` mediumint(11) NOT NULL,
    `Date_ID` mediumint(11) NOT NULL,
    PRIMARY KEY (`ID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

    --
    -- Dumping data for table `dealers_visit_lookup`
    --

    INSERT INTO `dealers_visit_lookup` (`ID`, `Dealer_ID`, `Date_ID`) VALUES
    (1, 1, 1),
    (2, 2, 2),
    (3, 2, 3),
    (4, 2, 4),
    (5, 3, 5);
    • CommentAuthorjay0316
    • CommentTimeApr 2nd 2009
     permalink
    Select Statement:

    SELECT
    `Dealer_BusinessName`,
    `Dealer_Address1`,
    `Dealer_City`,
    `Dealer_Zip`,
    `Dealer_State`,
    `Dealer_Zip`,
    `Completed_By`,
    `Date`

    FROM dealers , dealers_visit_lookup , dealers_visit

    WHERE dealers.Completed_By LIKE '%jason%' AND (dealers.Dealer_ID =dealers_visit_lookup.Dealer_ID ) AND (dealers_visit_lookup.Date_ID =dealers_visit.ID ) ORDER BY `dealers`.`Dealer_BusinessName` DESC
Add your comments
    Username Password
  • Format comments as (Help)