guitarist809 Posted January 6, 2007 Share Posted January 6, 2007 Yea, i can't do these for my life, if somebody could explain how to do one and how to get the data it returns. (what it would return in php using mysql_fetch_assoc()). Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/ Share on other sites More sharing options...
fenway Posted January 6, 2007 Share Posted January 6, 2007 How about some same table structures? Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-154498 Share on other sites More sharing options...
guitarist809 Posted January 7, 2007 Author Share Posted January 7, 2007 Ok, i'll get the data, but there are like 9 tables to be linked together... Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-155273 Share on other sites More sharing options...
guitarist809 Posted January 7, 2007 Author Share Posted January 7, 2007 OK, here are the tables that I currently have:[activities] - Contains all sorts of activities+--------------+activity_id - e.x., 1category - climbsubcategory - climbingsummaryrpt - yesabrev - clmb[locations] - all sorts of locations in the world+--------------+location_id //1location //Mount Everestcity //N/Astatecountry notes //high mountian[trips] - all tables link here, after here+-------------+trip_id //1location_id //1 (links to table location, location would be Mount Everest)trip_date // day trip was on[trips_activities] - activities completed by users in database+-------------+activity_id //id for indextrip_id //links to trip tableact_id //links to activities tableuser_id //links to users (table specified below)[trips_comments] - comments left by each user on each trip+-------------+comment_id //indextrip_id //links to tripuser_id //links to users (table will be specified blow)comment //the comment by that user[trips_participants]+----------------+participant_id //indextrip_id //links to tripuser_id //links to the users table which will be specified next[users]+-------------+user_id //indexusername //username for loginname //users namepassword //users passwordconfig_sys //permissionsconfig_trip //permissionsWow, there's like 4 more tables, but i think i can figure it out if i see an example.This is what im trying to do:Grab the trips in order by date ASC, then get all the users who went on the trip (table: trips_participants), then grab the comments left by those users(table: trips_comments), then grab all activities for each user (table trips_activities), then get all the names of the activities (table: activities), then get the location of the trip (table: trips), then get the name of the location (table: locations).Is this even possible with a join?Thanks,Matt :D Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-155293 Share on other sites More sharing options...
hvle Posted January 8, 2007 Share Posted January 8, 2007 is this your homework? Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-155447 Share on other sites More sharing options...
guitarist809 Posted January 8, 2007 Author Share Posted January 8, 2007 no...Its so I can keep track of the activities that i do... Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-155591 Share on other sites More sharing options...
hvle Posted January 8, 2007 Share Posted January 8, 2007 first of all, I think the database design you had is well structured and binded. Good design.You do not need more than 3 joins level to get what you wanted.Here is 1 example of using join, there are many type of join: left join, right join and join. So, I'm not sure about restriction of each table.This is one example:This query return a user's name, user's comment, trip activities and trip id:[code]"select users.username as p_username, trips_comments.comment as p_comment, trips_activities.activity_id as p_activity_id, trips_comments.trip_id as p_trip_id from users join trip_comments on users.user_id = trips_comments.user_id join trips_activities on users.user_id = trip_activities.user_id;[/code]I wrote this merely by looking at table structure. If it doesn't work, post both query and error.if you need a simple example on a specific thing, let me know also. Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-155618 Share on other sites More sharing options...
fenway Posted January 8, 2007 Share Posted January 8, 2007 Why have different trips tables? Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-156062 Share on other sites More sharing options...
guitarist809 Posted January 11, 2007 Author Share Posted January 11, 2007 Sorry, I STILL have not had time to test this out :( (been busy).I was just wondering, are joins significantly faster then doing the 10 query "SELECT this FROM table WHERE it='that'"? (the page took 15 minutes to load that way)...Just wondering Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-158348 Share on other sites More sharing options...
fenway Posted January 11, 2007 Share Posted January 11, 2007 That's too general a question... you can have very fast joins, and very fast selects... Link to comment https://forums.phpfreaks.com/topic/33062-mysql-join/#findComment-158611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.