Jump to content

Need Help !!


sierra_senthil

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/499-need-help/
Share on other sites


$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...

Link to comment
https://forums.phpfreaks.com/topic/499-need-help/#findComment-1679
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.