sierra_senthil Posted May 23, 2003 Share Posted May 23, 2003 Hi All My SQL Ver : 3.23.55-nt I have one table emp with 2 cols (userid,bossid ), can someone help me writing the query to find out one user is boss of how many like in this userid 16 is boss for 2 and userid12 is boss of 3 eg: USERID TOTAL 16 2 13 3 17 0 (Geting this row is imp for me. i mean the ) I should also be able to get total as 0 if the the user is not the boss of anyone..(as per my data) Thanks In Advance.. Sierra ************************************** create table emp (userid int,bossid int) insert emp values(12,0) insert emp values(13,12) insert emp values(16,12) insert emp values(17,12) insert emp values(18,13) insert emp values(19,13) insert emp values(20,13) insert emp values(23,16) insert emp values(24,23) insert emp values(26,23) insert emp values(27,23) insert emp values(28,16) insert emp values(29,26) insert emp values(30,26) insert emp values(31,30) insert emp values(32,31) Quote Link to comment https://forums.phpfreaks.com/topic/499-need-help/ Share on other sites More sharing options...
holiks Posted May 23, 2003 Share Posted May 23, 2003 $queried_boss_id = 12; $sql = "select * from emp where bossid = \'$queried_boss_id\'"; if(mysql_num_rows($sql) < 1) { $employees = \'No one\'; $count = \'0\'; } else { while($row = mysql_fetch_array($sql)) { $employees .= \' \'.$row[\'userid\']; $count++; } } print "He is boss of $count"; print "Their ideez being $employees"; //untested ..hope this is going your way... Quote Link to comment https://forums.phpfreaks.com/topic/499-need-help/#findComment-1679 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.