lol - thx dagon............ (I have weird logic.).
The user who is using this wanted a overview type page where he could quickly change things.
The maximum schedules per engineer is 7 - (thus 7 drop down boxes).
The pages are organised by date.
whole page code:
<?php
include ('includes/connection.php');
$i = 0;
$a = 0;
$b = 0;
$loop = 0;
$search[] = NULL;
include("includes/header.php");
include("includes/htmlhead.php");
$date = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
$cus_id2 = NULL;
$just_added = 0;
$id[] = NULL;
$eng[] = NULL;
if($date != NULL){
$date1 = explode("-", $date);
}
?>
<h1 align="center">
<br />
<br />
<br />
<br />
<br />
Assign Engineers to Customers:
</h1>
<br/>
<br />
<br /> <h2>
Date selected: <?php echo $date1[2]."-".$date1[1]."-".$date1[0]; ?> </h2> <br /> <br />
<table width="70%" border="0">
<form action="ass_eng_2.php" method="post" enctype="application/x-www-form-urlencoded">
<?php
$query = "SELECT FName, LName, engineer_id FROM engineer WHERE level_of_access = '2';";
//echo $query."<br/>";
$result = mysql_query($query);
check($result);
while ($row = mysql_fetch_array($result)) {
$eng_fname = $row[0];
$eng_lname = $row[1];
$eng_id = $row[2];
?>
<td rowspan="7" width="20%"><?php echo $eng_fname." ".$eng_lname;?> </td>
<?php $eng[$b] = $eng_id; ?>
<input name="eng[]" type="hidden" value="<?php echo $eng[$b];?>" />
<?php while($i <= 6){ ?>
<td width="10%">
<select id="<?php echo $value[$a]; ?>" name='value[]'>
<option value="0"> assign engineer </option>
<?php
$query2 = "SELECT c.cus_id, c.FName, c.LName FROM customer c LEFT JOIN customer_call a ON c.cus_id = a.cus_id WHERE c.case_closed = 'no' AND agreed_date = '".$date."' OR c.case_closed = 'no' AND agreed_date2 = '".$date."';";
$result2 = mysql_query($query2);
check($result2);
while ($row = mysql_fetch_array($result2)) {
$cus_id1 = $row[0];
$fName = $row[1];
$lName = $row[2];
$query1 = "SELECT a.cus_id FROM type_of_install a LEFT JOIN customer_call c ON a.cus_id = c.cus_id WHERE engineer_id = '".$eng_id."' AND agreed_date = '".$date."' AND a.cus_id = '".$cus_id1."' OR engineer_id2 = '".$eng_id."' AND agreed_date = '".$date."' AND a.cus_id = '".$cus_id1."';";
$result3 = mysql_query($query1);
check($result3);
while ($row = mysql_fetch_array($result3)) {
$cus_id2 = $row[0];
if($just_added == 0){
if(in_array($cus_id2,$search)){
}else{
$search[$loop] = $cus_id1;
$loop = $loop + 1;
//$q1 = $query1;
$just_added = 1;
?> <option value="<?php echo $cus_id2;?>" selected="selected"> <?php echo $fName." ".$lName; ?> </option>
<?php
}
}
}
?>
<option value="<?php echo $cus_id1;?>"> <?php echo $fName." ".$lName; ?> </option>
<?php
} $just_added = 0; ?>
</select>
</td>
<td>..... clear...<?php echo $a; ?>....... <input type="checkbox" name="delete[]" value="<?php echo $cus_id1;?>" /> </td>
</tr>
<tr>
<?php $a = $a + 1; $i++;
}
?> <tr> <td colspan="3"> </td> </tr> <?php
$i = 0;
$loop = 0;
$search[] = NULL;
$search = NULL;
$b = $b + 1;
$just_added = 0;
}
?>
<tr> <td colspan="2" align="right"> <input name="submit" type="submit" value="submit" /> </td> </tr>
<input name="date" type="hidden" value="<?php echo $date; ?>" />
</form> </table> </body>
</html>
This is basicly what I was trying on the next page.
<?php
include ('includes/connection.php');
include("includes/header.php");
$a = 0;
$b = 7;
$x = 0;
$eng3 = NULL;
$eng4 = NULL;
$date= $_POST['date'];
$value1 = count($_POST['value']); //(or $_GET, depending on what you use)
for ($i=0; $i<$value1; $i++){
$value[$i]= $_POST['value'][$i];
}
$delete1 = count($_POST['value']); //(or $_GET, depending on what you use)
for ($i=0; $i<$value1; $i++){
$value[$i]= $_POST['value'][$i];
}
foreach($_POST['eng'] AS $eng){
///////////////////////////// GET ENG ID FOR RELEVENT CUS_ID FIELD ////////////////////////////////
while($a < $b ){
$query = "SELECT engineer_id, engineer_id2 FROM type_of_install WHERE cus_id = '".$value[$a]."';";
$result1 = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result1)) {
$eng1 = $row[0];
$eng2 = $row[1];
///////////////////////////////////////////////////////////////////
// Clear an engineer
///////////////////////////////////////////////////////////////////
if(isset($_POST['delete'][$a])){
//// Eng is primary so remove /////
if($eng == $eng1){
///// make 2nd = 1st and remove 2nd. ////////////////////////////
$update = "UPDATE `type_of_install` SET `engineer_id` = '". $eng2 ."', `engineer_id2` = NULL WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
$update = "UPDATE `install` SET `engineer_id` = '". $eng2 ."', `engineer_id2` = NULL WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
echo "remove primary <br/>";
//// Eng is 2nd so remove /////
}else if($eng == $eng2){
///// make 2nd = 1st and remove 2nd. ////////////////////////////
$update = "UPDATE `type_of_install` SET `engineer_id2` = NULL WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
$update = "UPDATE `install` SET `engineer_id2` = NULL WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
echo "remove 2nd <br/>";
}
$a = $a + 1;
}else {
///////////////////////////////////////////////////////////////////
////////// Clear an engineer ---- END!!!
///////////////////////////////////////////////////////////////////
if($value[$a] == 0){
//No engineer selected - DO NOTHING!
}else{
//ENGINEER IS SELECTED
if(($eng == $eng1) || ($eng == $eng2)){
//echo "TRUE";
//ENGINEER IS ALREADY IN THERE -- LEAVE HIM IN THERE -- DO NOTHING
}else{
//IS PRIMARY EMPTY
if($eng1 == NULL || $eng1 == 0 || $eng1 == ""){
$update = "UPDATE `type_of_install` SET `engineer_id` = '". $eng2 ."', `engineer_id2` = '". $eng ."' WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
$update = "UPDATE `install` SET `engineer_id` = '". $eng2 ."', `engineer_id2` = '". $eng ."' WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
//IS 2ND EMPTY
}else if($eng2 == NULL || $eng2 == 0 || $eng2 == ""){
$update = "UPDATE `type_of_install` SET `engineer_id2` = '". $eng ."' WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
$update = "UPDATE `install` SET `engineer_id2` = '". $eng ."' WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
//NO EMPTY DO THIS
}else{
$update = "UPDATE `type_of_install` SET `engineer_id` = '". $eng2 ."', `engineer_id2` = '". $eng ."' WHERE `cus_id` = ".$value[$a].";";
$result = mysql_query($update)or die("Query failed with error: ".mysql_error());
echo $update."<br/> <br/>";
}// END UPDATED!!
}
}
}
}
echo $a."<br/>";
$a = $a + 1;
}
$b = $b + 7;
}
?>
But that doesn't work.
So what I want to go for is
if(delete == true)
sql = remove eng FROM install;
but I am running into problems....
PLEASE PLEASE try to help me..... I really am hopeless!
Kindest Regards
David