Jump to content


Photo

Need Help !!


  • Please log in to reply
1 reply to this topic

#1 sierra_senthil

sierra_senthil
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 23 May 2003 - 12:22 PM

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)

#2 holiks

holiks
  • Members
  • PipPipPip
  • Advanced Member
  • 83 posts

Posted 23 May 2003 - 12:54 PM


$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...
__________________________________________________________[br]$php = array('..a stack', '...once you pop', '...you don't stop');




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users