Jump to content

Recommended Posts

I'm trying to:

$query="SELECT fname, lname FROM employees WHERE employee_id=$employee_id";

 

echo "fname lname";

 

Right now the page displays the employee ID, but I need it to display the employee's name.

 

 

$query="SELECT ad_order.company company, job_log.employee_id employee_id, job_log.time time, job_log.action action FROM ad_order LEFT JOIN (job_log) ON (job_log.ad_id=ad_order.id) WHERE ad_order.cust_id=$table_id ORDER BY company,time";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))

{
$company = $row['company'];
$time = $row['time'];
$employee_name = $row['employee_id'];
if ($employee_name=="")
$employee_name = "No Entry";
else
$employee_name = $row['employee_id'];
$action = $row['action'];
if ($action=="")
$action = "No Entry";
else
$action = $row['action'];
$showtime = date('m/d/y-h:m:s',$time);
if ($showtime=="12/31/69-06:12:00")
$showtime = "No Entry";
else
$showtime = date('m/d/y-h:m:s',$time);

echo "$company - $employee _name - $showtime - $action";
}

Well, you don't have fname and lname selected in your query, and you have $employee_name set to equal $row['employee_id'].

 

$query="SELECT ad_order.company company, job_log.employee_id employee_id, job_log.time time, job_log.action action, fname, lname FROM ad_order LEFT JOIN (job_log) ON (job_log.ad_id=ad_order.id) WHERE ad_order.cust_id=$table_id ORDER BY company,time";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))

{
$company = $row['company'];
$time = $row['time'];
$employee_name = $row['fname']." ".$row['lname'];
if ($employee_name=="")
$employee_name = "No Entry";
else
$employee_name = $row['fname']." ".$row['lname'];
$action = $row['action'];
if ($action=="")
$action = "No Entry";
else
$action = $row['action'];
$showtime = date('m/d/y-h:m:s',$time);
if ($showtime=="12/31/69-06:12:00")
$showtime = "No Entry";
else
$showtime = date('m/d/y-h:m:s',$time);

echo "$company - $employee_name - $showtime - $action";
}

Not tested.

 

Is that what you wanted?

 

Edit: Oops. Forgot to do that. ;)

Garath531's code was basically correct..

 

except

you forgot to remove the old  $employee_name code, thus it being reset incorrectly

 

<?php
$query="SELECT ad_order.company company, job_log.employee_id employee_id, job_log.time time, job_log.action action, fname, lname FROM ad_order LEFT JOIN (job_log) ON (job_log.ad_id=ad_order.id) WHERE ad_order.cust_id=$table_id ORDER BY company,time";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))

{
$company = $row['company'];
$time = $row['time'];
$employee_name = $row['fname']." ".$row['lname'];
//removed lines from here
$action = $row['action'];
if ($action=="")
$action = "No Entry";
else
$action = $row['action'];
$showtime = date('m/d/y-h:m:s',$time);
if ($showtime=="12/31/69-06:12:00")
$showtime = "No Entry";
else
$showtime = date('m/d/y-h:m:s',$time);

echo "$company - $employee_name - $showtime - $action";
}
?>

Sorry about that. The employee_id is being pulled from the job_log table.

After I get the employee_id I then need to query the employees table with

the employee_id to get the employees fname and lname.

 

 

Page excuted in order:

 

query ad_order and job_log;

query employees with reuslts from job_log query;

{

echo results from queries;

}

<?php
$query="SELECT ad_order.company company, job_log.employee_id employee_id, job_log.time time, job_log.action action FROM ad_order LEFT JOIN (job_log) ON (job_log.ad_id=ad_order.id) WHERE ad_order.cust_id=$table_id ORDER BY company,time";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))

{
$company = $row['company'];
$time = $row['time'];
$employee_id = $row['employee_id'];
if ($employee_id=="")
$employee_id = "No Entry";
else
$employee_id = $row['employee_id'];
$action = $row['action'];
if ($action=="")
$action = "No Entry";
else
$action = $row['action'];
$showtime = date('m/d/y-h:m:s',$time);
if ($showtime=="12/31/69-06:12:00")
$showtime = "No Entry";
else
$showtime = date('m/d/y-h:m:s',$time);
        $query2 = "SELECT * FROM table WHERE employee_id = '$employee_id'";
        $result2 = mysql_query($query2) or die(mysql_error());
        while($row2 = mysql_fetch_assoc($result2)) 
        {
                 $employee_name = $row2['fname']." ".$row2['lname'];
        }
echo "$company - $employee _name - $showtime - $action";
}
?>

 

Something like that?

DUDE!!! Your a flippin genius!!!!

 

$query2 = "SELECT * FROM employees WHERE employee_id = '$employee_name'";
       $result2 = mysql_query($query2) or die(mysql_error());
       while($row2 = mysql_fetch_assoc($result2)) 
       {
                $employee_name2 = $row2['fname']." ".$row2['lname'];
       }

 

Thanks everyone!!

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.