Printable Version of Topic

Click here to view this topic in its original format

Dream.In.Code _ Databases _ linking tables

Posted by: peter yianni 17 Jun, 2009 - 10:57 AM

ok heres what i have
i have my database set up
and i need to link several tables to
which need to be autofilled when somehits a create button
i have the generator to autofill the vales but i need to somhow get that linked with the createbuton
which then has to send the details to mysql to be saved then has to resend the same details that where just created to a page where the user that just hit the create button will have as theres

am i making sence here because im giving myself a headache just thinking about it lol


Posted by: CamoDeveloper 17 Jun, 2009 - 03:41 PM

What language are you using for the front end?

Also, what version of MySQL are you running? If you can support Stored Procedures (Routines) then make one that creates a table and submits the data to a specified table you have setup already. Then, create another Stored Procedure to withdraw the data from that table and post it to where you want it.

Did that make any sense?

~Camo

Posted by: peter yianni 17 Jun, 2009 - 04:03 PM

QUOTE(CamoDeveloper @ 17 Jun, 2009 - 03:41 PM) *

What language are you using for the front end?

Also, what version of MySQL are you running? If you can support Stored Procedures (Routines) then make one that creates a table and submits the data to a specified table you have setup already. Then, create another Stored Procedure to withdraw the data from that table and post it to where you want it.

Did that make any sense?

~Camo


ok let me show u

SELECT *
FROM users, horse_stats, jocky_stats
WHERE users.stable_name = jocky_stats.stable_name= horse_stats. stable_name = users.user_name

ok i am geting them up but getting to many results like its shown the stable name three times i want to join so it just shows the stable name with there horses and jocks

ok i am using dreamweaver cs4

Posted by: CamoDeveloper 17 Jun, 2009 - 08:29 PM

With that statement you're telling the database to return those values from all the tables separately. You need to join them together using the stable_name column. You may need to adjust this a little depending on the results you get. This is what it should look like :

CODE

-- I usually add styling to my statements for easier reading
SELECT
    *
FROM
    -- I made users the primary table, but you could make any of these the primary
    users
    -- I'm joining them on the common column name stable_name. To join tables they need to have a column that both tables use so the database can use it as a checking point
    LEFT JOIN horse_stats ON users.stable_name = horse_stats.stable_name
    LEFT JOIN jocky_stats ON users.stable_name = jocky_stats.stable_name
    -- You might need to change LEFT to either RIGHT or INNER depending on the results you recieve. LEFT should work just fine
WHERE
    -- Only selects the data that matches
    users.stable_name = horse_stats.stable_name
    AND users.stable_name = jocky_stats.stable_name
-- The entire WHERE can be removed if you want, it just helps with grabbing certain data


Let me know if you get any errors or have any more questions.

~Camo

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)