manalnor Posted March 30, 2011 Share Posted March 30, 2011 Hello friends, it is very complicated and spent alot of time thinking and i can not do it let say we have 2 tables Table1 (id,user,code) example (1,user1,code1) (2,user1,code2) (3,user2,code3) (4,user3,code4) this means user1 has added code1 and code2 Table2 (id,code,hits) example (1,code1,100) (2,code2,50) (3,code3,40) (4,code4,80) this means code1 has 100 hits and code2 has 50 hits I wanna get [ the sum of hits of codes that added by only user1 ] it will be 100+50=150 Hits i've an idea 1- query for all codes added by user1 at table 1 and keep the results as array and it should be (code1,code2) 2- then get the sum of hits for all codes in that array (code1,code2) from table 2 Now the problem how to say it in MYSQL thanks Quote Link to comment https://forums.phpfreaks.com/topic/232169-how-to-say-this/ Share on other sites More sharing options...
sunfighter Posted March 31, 2011 Share Posted March 31, 2011 Since the number of hits are associated with the code, why have two tables? Just add the hits column to table one. Then to find total hits to one person query an ADD hits WHERE user = user1 Quote Link to comment https://forums.phpfreaks.com/topic/232169-how-to-say-this/#findComment-1195261 Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 Seems more of a SQL question rather than PHP, moving. Quote Link to comment https://forums.phpfreaks.com/topic/232169-how-to-say-this/#findComment-1195274 Share on other sites More sharing options...
cssfreakie Posted April 1, 2011 Share Posted April 1, 2011 read the tutorial of phpfreaks about joins, I am pretty sure that is what you need. Quote Link to comment https://forums.phpfreaks.com/topic/232169-how-to-say-this/#findComment-1195336 Share on other sites More sharing options...
kickstart Posted April 1, 2011 Share Posted April 1, 2011 Hi Something like this would do it SELECT user, COUNT(hits) FROM Table1 INNER JOIN Table2 ON Table1.code = table2.code GROUP BY user All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/232169-how-to-say-this/#findComment-1195508 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.