Skip to main content
Inspiring
August 1, 2007
Question

Dynamic ToolTip

  • August 1, 2007
  • 3 replies
  • 895 views
I did static tooltip before....i want to do Dynamic Tooltip.

I got two tables....
Employee Table

ID Name Sal
10 Don 2000
11 Sam 1800
12 Bill 2100


Department Table

ID EmpID DeptName
1 10 Math
2 11 Physics
3 12 Science
4 12 Math


Result of all employees.....
10 Don 2000
11 Sam 1800
12 Bill 2100


when user move cursor on the top of Employee name field, i want to show department name employee associated with as tooltip.

How can i do that?.

Bill is associated two department.....which query will give me his two department name to display in tooltip?

select id,name,sal from employee

will be list of employee......how can i get department assosicated with employee without showing duplicate of employee records?.

then finally department name...i want to show as Dynamic tooltip.

Thanks for all ur help...
    This topic has been closed for replies.

    3 replies

    Inspiring
    August 1, 2007


    Javagene wrote:

    > ....which query will give me his two
    > department name to display in tool tip?

    1) - basic sample using GROUP attribute of cfoutput tag

    select e.*, d.department_name
    from employees e inner join departments d on e.employee_id = d.employee_id
    order by whateveryouwant

    then use the GROUP attribute in the cfoutput

    2) - will probably be more usable in your case of tooltips

    have 1 master join query that selects ALL employees and departments
    have 1 QoQ selecting DISTINCT employee rows from master query
    cfoutput this QoQ to display your employee info
    within the cfoutput have another QoQ select departments of current
    employee from master query
    loop through the second QoQ to populate your tooltip


    ---
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com
    Inspiring
    August 2, 2007
    Javagene,

    Using Azadi's suggested GROUP method in your query, you can use the TITLE attribute for displaying your Tooltip for IE ONLY.

    Inspiring
    August 2, 2007
    If you are using MS SQL server, you can use (execute) this User Defined Function in your SQL server to dynamically get the list of department(s) for each employee:

    CREATE FUNCTION dbo.fn_GetDepartmentNames (
    @Employee_ID int
    )
    RETURNS varchar(3000)

    AS
    BEGIN
    DECLARE @Department_List varchar(3000)
    SET @Department_List = ''

    SELECT @Department_List = @Department_List + CASE WHEN @Department_List = '' THEN '' ELSE ', ' END
    + LTRIM(RTRIM(dept.DeptName))
    FROM Employee emp
    JOIN Department dept ON emp.ID = dept.EmpID
    WHERE emp.ID = @Employee_ID
    ORDER BY emp.Name --or whatever you want to order by

    RETURN @Department_List

    END

    Then in your main query:
    (I'm assuming you don't have any employee duplicates in your Employee table. But you can use the GROUP BY to avoid duplicates.)

    SELECT emp.Name, DeptNames = dbo.fn_GetDepartmentNames(emp.ID)
    FROM Employee emp
    ORDER BY emp.Name --or whatever you want to order by

    If you output this query, you should get a list of department(s) for each employee in your result.

    <table border="1" cellpadding="1" cellspacing="0">
    <tr>
    <td>Employee Name</td>
    </tr>
    <CFOUTPUT QUERY="MyMainQuery">
    <tr>
    <td TITLE="#DeptNames#">#Name#</td> <!--- TITLE attribute is used here to display your Tool Tip, but this is IE ONLY. --->
    </tr>
    </CFOUTPUT>
    </table>
    JavageneAuthor
    Inspiring
    August 1, 2007
    My output is like this ......List of all employees...

    10 Don 2000
    11 Sam 1800
    12 Bill 2100

    On mouse over on name of employee...i want to show all department employee belongs to. How can i do this?.

    Here is the code i used for static tooltip...this works in IE and FF. Now i want to make it work for only IE.


    <a onmouseover="return escape('<strong>'+'Cities'+'</strong>'+': NY,LA+'<br><br>'+'<strong>'+'Roadway'+'</strong>'+':101,95 ')">

    Then i used wz_tooltip.js.
    Inspiring
    August 1, 2007
    quote:

    Originally posted by: Javagene
    On mouse over on name of employee...i want to show all department employee belongs to. How can i do this?.


    If an employee can belong to more than one department you need a many to many relationship.
    JavageneAuthor
    Inspiring
    August 1, 2007
    One to many is enough in my situation.

    One employee belongs to many department. One to many.

    How can do a dynamic tooltip?.
    Inspiring
    August 1, 2007
    Take a look at your data structure. What happens if you get more than one employee in any department?