jrws Posted March 2, 2009 Share Posted March 2, 2009 Hi guys I was wondering how I would implement the ability to see what posts a user has made. I would be thinking a join, but don't know which join to use, as they are confusing to me. Basically I want to make it so that when you are on the users page, it will say stuff like: Username: blah Email: blah@blah.com Posts: number of posts, and or links to the posts Mind you I just want to test this thing out, because as soon as I understand how to do it I can perform other functions. So if anyone can explain in an easy way or help me that would be great. I have already looked at many tutorials about left joins and right joins and joins in general. However like I have stated, I don't know how to use them properly. Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/ Share on other sites More sharing options...
MadTechie Posted March 2, 2009 Share Posted March 2, 2009 read here SQL JOINS Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-774562 Share on other sites More sharing options...
jrws Posted March 3, 2009 Author Share Posted March 3, 2009 Yeah I know SQL joins, but I want someone to help me, for example telling me which would be the best join and why. I know what joins are, I just don't know how to use them. But thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-775276 Share on other sites More sharing options...
MadTechie Posted March 3, 2009 Share Posted March 3, 2009 If you read the whole page it tells you everything you need to know, including what JOINs to use for what! and how to use them! Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-775904 Share on other sites More sharing options...
jrws Posted March 4, 2009 Author Share Posted March 4, 2009 I really don't think you quite understand what my delema is. I know what the joins are, but I don't know what the format for this situation would be for what I want, and I can't seem to find any information on it. Thanks again, I guess I will just have to look harder. Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776169 Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 jrws, I hear what you're saying. The things got me confused as well to begin with. I knew what they were and how they can help but could never get them working without someone else fixing the queries for me at which point I'd be lost as to what the changes did and why. A normal query queries one table. A normal join (can't remember the term for it) is used when two tables always contain data that can be matched. For example, an "albums" table and a "track listings" table - albums always have tracks even if its only one. A left join is handy for using when the second table doesn't always contain data to match with the first. For example, a "track listing" table and a "remix name" table as not all tracks on an album would be remixed. Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776174 Share on other sites More sharing options...
jrws Posted March 4, 2009 Author Share Posted March 4, 2009 Alright thanks for that, that helps a little, could you perhaps help me then with figuring out what records it would be for a user table and post id So for example id of user links to the post u_id But I want it so that it counts how many articles the user would of posted, so in that case how many times the same u_id appears. How would I do this? Would this be a join or a normal where clause? Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776195 Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 I must admit you've lost me there, but my guess is something like... SELECT COUNT(p.*) FROM users AS u LEFT JOIN posts AS p ON u.id=p.userid Not sure that'd work - never used COUNT() with a LEFT JOIN before! Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776205 Share on other sites More sharing options...
jrws Posted March 4, 2009 Author Share Posted March 4, 2009 Sorry didn't mean to lose you. Basically I don't know if I want a where clause like 'SELECT * FROM $table WHERE something = '$something'; Or if I needed a join What I want to do is find out how many posts as user has made, the way I have made the tables they only would share two things, the author as the username of the poster and the user id as the id of the user (am I making sense?) So then I would like to count how many times the user id is repeated in the news table, perhaps author would be better. After that I want PHP to spit out the results. I am going to see if I can find some open source software which may have the answer. Thanks again, Hopefully I made a bit more sense this time. Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776215 Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 A little more, maybe something like this: SELECT COUNT(p.*) FROM users AS u LEFT JOIN posts AS p ON u.id=p.userid WHERE u.id='12345' Where "12345" is the ID number of the user in question. Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776218 Share on other sites More sharing options...
jrws Posted March 4, 2009 Author Share Posted March 4, 2009 Alright I will give it a try Quote Link to comment https://forums.phpfreaks.com/topic/147548-news-system/#findComment-776229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.