Forum Moderators: coopster

Message Too Old, No Replies

maximum Status

         

franches

6:15 am on Oct 15, 2004 (gmt 0)

10+ Year Member



hi,
Anyone who has an idea on how to query the maximum status of my database for a certain map_number. I have fields in my table such as Date, Mapnumber, Employee_number, Workhrs and Status. Everyday the user will input the status of the map he/she is working until it is finished or reached 100%. My goal is if the user enter 10% in the Status yesterday with 01(this is the Mapnumber) and when the user fills up the form today he/she is not allowed to input in the Status less than 10%. If she enters less than 10% then there should be something to inform the user that he/she is not allowed to input less than 10%. I don't have any idea what will be the code for it. If there someone here who could help me thanks a lot.

franches

1:52 am on Oct 16, 2004 (gmt 0)

10+ Year Member



I really need help my code is not working.

if (isset($_POST['status']))
{
$query = "select max(Status) from StatusTable where Mapnumber = '$mapnumber'";
$rs = mysql_query($query) or die(mysql_error());
$rowStatus = mysql_fetch_row($rs);
{
if ($rowStatus > $status)
{
echo "The Status entered should not be less than '$rowStatus!'";
}
}
else

$timestamp = "{$_POST['fromYear']}-{$_POST['fromMonth']}-{$_POST['fromDay']}";

$sql= "insert into StatusTable (ActDate, PIN, Activity, RegHours, Status, Mapnumber) values ('" . $timestamp . "','" . $_SESSION['username'] . "','" . $_POST['activity'] . "','" . number_format($_POST['work_hours'], 2) . "','" . $_POST['status'] . "','" . $_POST['mapnumber'] . "')";
mysql_query($sql) or die('error making query: ' . mysql_error());

jatar_k

3:23 am on Oct 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you have a small problem with this line

$rowStatus = mysql_fetch_row($rs);

I assume it will only select a single row with a max() so try the same line this way

if ($rowStatus = mysql_fetch_row($rs));

only a guess since I see an opening brace after it and nothing that needs a brace, I would think you should have a parse error actually

another thing is I think you need a brace after

else {

and then one at the end of the code you pasted unless there is something more in the else

franches

5:22 am on Oct 18, 2004 (gmt 0)

10+ Year Member



I am able to display the message but it also inserts the data in my database which is not supposed to happen. here's my code.

if (isset($_POST['status']))
{
$query = "select Status from StatusTable where Mapnumber = '$mapnumber'";
$rs = mysql_query($query) or die(mysql_error());
$rowStatus = mysql_fetch_row($rs);
{
if ($rowStatus[0] > $_POST['status'])
{
echo "The Status entered should not be less than '$rowStatus[0]!'";
}
else
$timestamp = "{$_POST['fromYear']}-{$_POST['fromMonth']}-{$_POST['fromDay']}";

$sql= "insert into StatusTable (ActDate, PIN, Activity, RegHours, Status, Mapnumber) values ('" . $timestamp . "','" . $_SESSION['username'] . "','" . $_POST['activity'] . "','" . number_format($_POST['work_hours'], 2) . "','" . $_POST['status'] . "','" . $_POST['mapnumber'] . "')";
mysql_query($sql) or die('error making query: ' . mysql_error());
}
}

jatar_k

5:29 am on Oct 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



did you try the changes I mentioned, those problem lines look exactly the same as the first time

franches

1:58 am on Oct 19, 2004 (gmt 0)

10+ Year Member



thanks it worked but in my form i've noticed eventhough the data is not inserted into my database the number of hours is subtracting like if i tried to input the 1 hr but the status is less than the status from my database so it is invalid. the 1 hr is deducted to my default 7.5 hrs.

And also I am facing another problem which is if the user logs out and decided to login again therefore the default should not be 7.5 but it should be the remaining number of hours for that date.

franches

1:59 am on Oct 19, 2004 (gmt 0)

10+ Year Member



what I mean is in my form the 1 hr is subtracted.