Jump to content

Retrieve data from one db to submit to another db


Zergman

Recommended Posts

So here's my issue.

 

I was given access to another DB to extract data from when submitting a form that submits to another DB.

 

In this new DB, there are 2 tables.

 

Table 1 is the primary table with employee data.

Table 2 is if the employee is assigned a temporary manager, it will be updated here.

 

What I need to accomplish is this.

 

On my form, they enter the ID number of the employee.  The form needs to check the manager name of both tables and if different use the one from Table 2.

 

I have no clue how to do this.  Was hoping that after the agent id field looses focus, it would execute the query to check the tables and populate the manager name field before the main form is submitted.  That way the users can enter the agent ID then tab off the field and it would fetch the manager name automatically. 

 

I hope this isn't confusing cause I know I sure am confused.

Link to comment
Share on other sites

The behaviour you describe (a dynamically populating form) is available through AJAX. Shall I move your topic to AJAX section?

 

Or do you also have problems with other parts of this application?

Link to comment
Share on other sites

Gotcha, i've tinkered enough and wasted enough time trying to figure this out myself :)

 

I got some example code from the guy who built the DB and uses these tables, he's just not accessible to help.

 

Here's the example he gave me.

function get_true_manager($employee_id){

include("system/db.php");
$emp_id=str_pad($employee_id,8,"0", STR_PAD_LEFT);

$db_sys_emp_sql="SELECT tbl1.employee_pdl_mgr_id, tbl2.manager_id ";
$db_sys_emp_sql.="FROM tbl1 ";
$db_sys_emp_sql.="LEFT JOIN tbl2 ON tbl1.employee_id = tbl2.employee_id ";
$db_sys_emp_sql.="WHERE tbl1.employee_id ='".$emp_id."' ";

$db_sys->SetFetchMode(ADODB_FETCH_ASSOC);// Return associative array
     	$rs_sys = &$db_sys->Execute($db_sys_emp_sql);

        if (!$rs_sys) {
                  print $db_sys->ErrorMsg();// 

while ($row_sys = $rs_sys->FetchNextObject()) {

$mgr_pdl=$row_sys->EMPLOYEE_PDL_MGR_ID;
        	       $mgr_other=$row_sys->MANAGER_ID;
        }
        
        if(is_null($mgr_other)){ 
$true_manager=$mgr_pdl;
        	}
        	else
        	{
$true_manager=$mgr_other;
        	}
        	
        return $true_manager;
}

 

Problem is I don't understand half of what this is doing and seems over complicated to what I need it to do.

 

I just need to have 1 box where the user will put in a numerical employee id and it will pull the manager id from the right table. .... ugh

Link to comment
Share on other sites

I really can't figure out why the guy built these tables like he did but whatever ....

 

Anyways let me better try to ask my question.

 

There is one DB that has 2 tables.  The main table (tbl1) stores all employee information.  The second table (tbl2) has a record in it if the an employee is assigned to another temp manager.

 

Both tables have indentical fields for the employee ID numbers (employee_id).

 

What I need this process too do is as follows.

1) Page loads that has 1 field in it

<input type="text" name="employee_id" id="employee_id" />

2) User enters a ID of an employee into the field and hits Search

3) It checks tbl2 for a record and if found, displays (manager_id)

... if no record is found

4) Pulls the record from tbl1 and displays (employee_pdl_mgr_id)

 

I know this isn't right and probably FAR from correct but its something

SELECT *
FROM tbl1, tbl2
WHERE tbl1.employee_id AND tbl2.employee_id = '%$employee_id%'

 

im at my wits end ... seems simple, yet I just can't get it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.