The full story:
I work for a company that sells ad space on restraunt table tops. Some of the restraunts and advertisers are pickier than others. The longer we spend on an ad the less we make (time is money). I have to find a way to determine how much time each ad and table is taking.
I can pull the ad time per ad by searching the job_log table for the ad_id's. I also need to know how long it takes to put the table together. This information is also in the jog_log table, but the table records don't have any information in the ad_id column so when I run the query it skips those records. The $table_id comes from a dropdown menu on a previous page.
select_table.php
<?php
include('include/user_check.php');
include('include/db_con.php');
$id = $_SESSION['track_id'];
$abc_current_tables = mysql_query("SELECT table_id , rest_name , set_no , status_3, dist_id FROM abc_tables WHERE status_2<'6' order by rest_name", $db_link);
$num_current_tables = mysql_num_rows($abc_current_tables);
?>
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" type="text/css" href="styles.css">
<TITLE>:: In-House Projects ::</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY BGCOLOR=#FFFFFF leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<div align="center">
<TABLE WIDTH=758 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<? include('include/top.php'); ?>
<TR height="516">
<TD valign="top" height="516">
<div align="center">
<form name="FormName" action="table_ad_time.php" method="post">
<b>Restaurants </b>(<? echo $num_current_tables; ?>)<br>
<select name="table_id" class="formTextbox" size="1">
<option value="">-- Select a Restaurant --</option>
<? while($row_current_tables = mysql_fetch_array($abc_current_tables)) {
$table_id = $row_current_tables['table_id'];
$rest_name = $row_current_tables['rest_name'];
$set_no = $row_current_tables['set_no'];
$dist_id = $row_current_tables['dist_id'];
$query_dist = mysql_query("SELECT fname, lname, sales_id FROM sales_rep WHERE sales_id = '$dist_id'", $db_link);
while ($row_dist_name = mysql_fetch_array($query_dist)){
$dist_lname = $row_dist_name['lname'];
$dist_fname = $row_dist_name['fname'];
}
?>
<option value="<?=$table_id;?>"><? echo $rest_name. " Set " .$set_no. "--" .$dist_lname. ", " .$dist_fname;?></option>
<? } ?>
</select><br>
<input type="submit" class="formTextbox" name="submit" value="Get Table Info"><br>
</form>
</body>
</html>
table_ad_time.php
<?php
include('include/user_check.php');
include('include/db_con.php');
$id = $_SESSION['track_id'];
?>
<html>
<BODY BGCOLOR=#FFFFFF leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<div align="center">
<TABLE WIDTH=758 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<? include('include/top.php'); ?>
<TR height="516">
<TD valign="top" height="516">
<div align="center">
<?php
$query="SELECT rest_name FROM abc_tables WHERE table_id=$table_id";
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$rest_name = $row['rest_name'];
}
?>
<?php
echo "<center>$rest_name<br><br></center>";
echo "<center>Table ID #$table_id<br><br></center>";
echo "<center><table border = '1' cellspaceing = '2' cellpadding = '4' width = '100%' bgcolor = '#999999'>";
echo "<tr><td width = '40%'><font color='#ffffff'>Company Name</font></td><td width = '20%'><font color='#ffffff'>Employee Name</font></td><td width = '20%'><font color='#ffffff'>Time</font></td><td width = '25%'><font color='#ffffff'>Action</font></td></tr>";
echo "</table><br></center>";
$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_name2 = $row['employee_id'];
$action3 = $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:i:s',$time);
$query2 = "SELECT * FROM employees WHERE employee_id = '$employee_name2'";
$result2 = mysql_query($query2);
while($row2 = mysql_fetch_assoc($result2))
{
$employee_name2 = $row2['fname']." ".$row2['lname'];
if ($employee_name2=="")
$employee_name2 = "No Entry";
else
$employee_name2 = $row2['fname']." ".$row2['lname'];
}
$query3 = "SELECT * FROM job_actions WHERE action_id = '$action3'";
$result3 = mysql_query($query3);
while($row3 = mysql_fetch_assoc($result3))
{
$action3 = $row3['action_name'];
if ($action3=="")
$action3 = "No Entry";
else
$action3 = $row3['action_name'];
}
echo "<center><table border = '0' cellspaceing = '0' cellpadding = '1' width = '100%' bgcolor = '#ffffff'>";
echo "<tr><td abbr = abbr_text width = '40%'>$company</td><td align = 'center' width = '20%'>$employee_name2</td><td width = '20%'>$showtime</td><td align = center width = '25%'>$action3</td></tr>";
echo "</table></center>";
}
echo "<br><br><br>";
mysql_close();
?>
</TD>
</TR>
</table>
</body>
</html>
here is a sample of my job_log table