matthewst Posted April 25, 2007 Share Posted April 25, 2007 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"; } Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/ Share on other sites More sharing options...
Garath531 Posted April 25, 2007 Share Posted April 25, 2007 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. Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/#findComment-238239 Share on other sites More sharing options...
MadTechie Posted April 25, 2007 Share Posted April 25, 2007 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/#findComment-238245 Share on other sites More sharing options...
matthewst Posted April 25, 2007 Author Share Posted April 25, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/#findComment-238254 Share on other sites More sharing options...
Garath531 Posted April 25, 2007 Share Posted April 25, 2007 <?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? Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/#findComment-238266 Share on other sites More sharing options...
MadTechie Posted April 25, 2007 Share Posted April 25, 2007 looks good Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/#findComment-238272 Share on other sites More sharing options...
matthewst Posted April 25, 2007 Author Share Posted April 25, 2007 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!! Link to comment https://forums.phpfreaks.com/topic/48650-solved-using-results-in-another-query-before-echo/#findComment-238274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.