#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    831
    Rep Power
    18

    Multiple fetch() in single while()


    Hi. I do apologize if this counts as a double post or w/e to my MySQL Post , but it is intended as more if the MySQL one is not possible. I need to write a single table, 10 columns from DB, in which the data is defined across like 6 DB tables.

    If this is not possible, I am asking here if maybe there is another option. Perhaps running 2 queries at the same time to each build half the table per pass of a while() loop or such. Any input would be greatly appreciated. Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    831
    Rep Power
    18
    Sorry if this doesn't help, n seems more a mess. The first column defines the HTML column name. The 2nd defines what I need to select to build the single row on the table. The THIS -> THAT defines an ID I can use to join/match items across the tables. Thank you very much for any help...

    Code:
    Customer    customers.`Customer Name`           servicecontractmain.`CustomerID` -> customers.`ID`
    Serial #    machines.`Serial Number`            servicecontractmain.`MachineID` -> machines.`ID`
    Username    servicecontractprospect.`Username`  servicecontractmain.`ProspectID` -> servicecontractprospect.`ID`
    Type        servicecontracttype.`ContractName`  servicecontractprospect.`ContractTypeID` -> servicecontracttype.`ID`
    Status      servicecontractprospect.`Purchased` servicecontractmain.`ProspectID` -> servicecontractprospect.`ID`
    Username    servicecontractcontract.`Username`  servicecontractmain.`ContractID` -> servicecontractcontract.`ID`
    Start       servicecontract.`Start`             servicecontractmain.`ContractID` -> servicecontract.`ID`
    End         servicecontract.`End`               servicecontractmain.`ContractID` -> servicecontract.`ID`
    EDIT: Wrong category, sry...
    Last edited by Triple_Nothing; August 7th, 2013 at 12:36 PM.
  4. #3
  5. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    It sounds like you just need to do a JOIN ?
    LinkedIn: Dave Mittner
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    831
    Rep Power
    18
    I've worked with JOINs before, but never more than 1 table. Not sure how I would enter multiple joins in the same query.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    38
    Rep Power
    3
    Originally Posted by Triple_Nothing
    I've worked with JOINs before, but never more than 1 table. Not sure how I would enter multiple joins in the same query.
    DId a quick Google search, you should do several JOIN like this:

    Code:
    SELECT Products.Title, Product_Lines.pl_Title, Manufacturers.man_Title  FROM Products 
    INNER JOIN Product_Lines ON Products.pl_ID = Product_Lines.pl_ID INNER JOIN Manufacturers ON Product_Lines.man_ID=Manufacturers.man_ID
    Just make sure to use the format TABLE.COLUMN in case of same column name in several tables. Hope it helps
  10. #6
  11. No Profile Picture
    Dazed&Confused
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2002
    Location
    Tempe, AZ
    Posts
    506
    Rep Power
    128
    Originally Posted by jaimitoc30
    DId a quick Google search, you should do several JOIN like this:

    Code:
    SELECT Products.Title, Product_Lines.pl_Title, Manufacturers.man_Title  FROM Products 
    INNER JOIN Product_Lines ON Products.pl_ID = Product_Lines.pl_ID INNER JOIN Manufacturers ON Product_Lines.man_ID=Manufacturers.man_ID
    Just make sure to use the format TABLE.COLUMN in case of same column name in several tables. Hope it helps
    You can streamline that quite a bit.

    Code:
    SELECT p.Title, pl.pl_Title, m.man_Title 
    FROM Products p
    JOIN Product_Lines pl ON p.pl_ID = pl.pl_ID
    JOIN Manufacturers m ON pl.man_ID=m.man_ID
    And if there won't always be a horizontal connection to Product_Lines or Manufacturers, but you still want to return the results from Products:

    Code:
    SELECT p.Title, pl.pl_Title, m.man_Title 
    FROM Products p
    LEFT JOIN Product_Lines pl ON p.pl_ID = pl.pl_ID
    LEFT JOIN Manufacturers m ON pl.man_ID=m.man_ID
    LinkedIn: Dave Mittner

IMN logo majestic logo threadwatch logo seochat tools logo