<?php
//If there has to be searched on systems $search_system will be true. Then the querie will be build first. Then all systems will be put
//in a resultset.
if($search_system==true){
//Building the querie. If a textbox is empty the string will be empty. If not, there will be one or two strings, the join string
//and the where string. This is going in two different parts of the querie.
//If there was a search on a firstcustomer, $search_firstcustomer will not be empty. There is a inner join string, because
//the systemtable will have to be linked to the salesordertable. This will be done with the salesorder_id.
if($search_firstcustomer!=""){
$sqlinner_systemsfirstcustomer = "INNER JOIN salesorder ON system.salesorder_id = salesorder.salesorder_id ";
$sqlwhere_systemsfirstcustomer = "AND salesorder.customer_id = '$search_firstcustomer' ";
}
else{
$sqlinner_systemsfirstcustomer = ""; $sqlwhere_systemsfirstcustomer = "";
}
//If there was a search on a user, $search_user will not be empty. There is no inner join string, because
//the user is located in the systemtable, so no link needed with another table.
if($search_user!=""){
$sqlwhere_systemsuser = "AND system.user_id = '$search_user' ";
}
else{
$sqlwhere_systemsuser = "";
}
//If there was a search on a lastcustomer, $search_lastcustomer will not be empty. There is a inner join string, because
//the systemtable will have to be linked to the servicetable and the service_reporttable. The link with the servicetable will be
//done with the salesorder_id and the line_id. The link with service_reporttable will be done with the optained report_id of the
//servicetable.
if($search_lastcustomer!=""){
$sqlinner_systemslastcustomer = "INNER JOIN service ON system.salesorder_id = service.salesorder_id AND system.line_id = service.line_id INNER JOIN service_report ON service_report.report_id = service.report_id ";
$sqlwhere_systemslastcustomer = "AND service_report.customer_id = '$search_lastcustomer' ";
}
else{
$sqlinner_systemslastcustomer = "";
$sqlwhere_systemslastcustomer = "";
}
//If there was a search on a systemnumber, $search_systemnbr will not be empty. There is no inner join string, because
//the number is located in the systemtable, so no link needed with another table.
if($search_systemnbr!=""){
$sqlwhere_systemssystemnbr = "AND part_nbr = '$search_systemnbr' ";
}
else{
$sqlwhere_systemssystemnbr = "";
}
//If there was a search on a systemdescription1, $search_systemdesc1 will not be empty. There is no inner join string, because
//the description is located in the systemtable, so no link needed with another table.
if($search_systemdesc1!=""){
$sqlwhere_systemssystemdesc1 = "AND part_desc1 = '$search_systemdesc1' ";
}
else{
$sqlwhere_systemssystemdesc1 = "";
}
if($search_systemdesc2!=""){
$sqlwhere_systemssystemdesc2 = "AND part_desc2 = '$search_systemdesc2' ";
}
else{
$sqlwhere_systemssystemdesc2 = "";
}
if($search_contractid!=""){
$sqlwhere_systemscontractid = "AND contract_id = '$search_contractid' ";
}
else{
$sqlwhere_systemscontractid = "";
}
if($search_locationid!=""){
$sqlinner_systemslocationid = "INNER JOIN location ON location.location_id = system.location_id ";
$sqlwhere_systemslocationid = "AND location.description_short LIKE '%".$search_locationid."%' ";
}
else{
$sqlinner_systemslocationid = "";
$sqlwhere_systemslocationid = "";
}
//Making the connection with the database.
$connection = mysql_connect($xsname, $xsuser, $xspass) or die($mysql_connect_error);
mysql_select_db($xsdb) or die($mysql_selectdb_error) or die($mysql_selectdb_error);
$systems = " SELECT system.salesorder_id,
system.line_id,
system.location_id,
system.user_id,
system.contract_id,
system.amount,
system.part_nbr,
system.part_desc1,
system.part_desc2,
system.date FROM system ". $sqlinner_systemsfirstcustomer.
$sqlinner_systemslastcustomer.
$sqlinner_systemslocationid.
"WHERE system.salesorder_id = system.salesorder_id ".
$sqlwhere_systemsfirstcustomer.
$sqlwhere_systemsuser.
$sqlwhere_systemslastcustomer.
$sqlwhere_systemssystemnbr.
$sqlwhere_systemssystemdesc1.
$sqlwhere_systemssystemdesc2.
$sqlwhere_systemscontractid.
$sqlwhere_systemslocationid;
$resultsystems = mysql_query($systems);
$numberofresultsystems = mysql_num_rows($resultsystems);
mysql_close($connection);
}
?>
<HTML>
<HEAD>
<STYLE>
<?php include 'include\style_body.php'; ?>
<?php include 'include\style_h1.php'; ?>
<?php include 'include\style_td.php'; ?>
</STYLE>
<TITLE>
<?php print $title_newservice1; ?>
</TITLE>
</HEAD>
<BODY>
print all boxes....I hope you understand this now...
</BODY>
</HTML>