PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 15th, 2004, 05:21 AM
franches franches is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 franches User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question maximum Status

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.

Reply With Quote
  #2  
Old October 15th, 2004, 08:48 AM
pocketsized pocketsized is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: Brunei
Posts: 26 pocketsized User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Doesn't sound too difficult. Just code a function to check that the new value isn't less than the value stored in the database. So if you call updateStatus ($id, $newStatus):

PHP Code:
function updateStatus ($id$newStatus)
 {
 
// Connect to Database.
 // ...
 
 // Retrieve the value of 
 // status currently in the database.
 
$sql "SELECT status FROM $tableName WHERE id=$id";
 
$oldStatus dbQuery ($sql);
 
   if (
$newStatus $oldStatus)
     
// The new status is less 
     // than the old status. Inform 
     // user
     
echo ("You cannot enter a value less than $oldStatus");
 
   else
     
// Update the status
     // ...
 


Reply With Quote
  #3  
Old October 15th, 2004, 08:52 PM
franches franches is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 franches User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

i've made this code but it is not working what it is supposed to do. kindly examine it.

Quote:

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 = $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());
}

Reply With Quote
  #4  
Old October 16th, 2004, 12:15 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
this line: if ($rowStatus > $status)
$rowStatus is an array... you need to reference a specific field...

I'd recommend modifying your query to read select max(Status) as status from StatusTable where Mapnumber = '$mapnumber' then changing that line to reference the proper element... if ($rowStatus['status'] > $status)

also, is $mapnumber a number? perhaps it shouldn't be in quotes in your query.
um, I was editting your code for my own readability, and there seems to be a mix up of brackets... what's the bracket above the IF statement I mentioned above?

This code is different than the code you posted as that INSERT statement will ALWAYS run... I assume you dont intend it to do so... but why not correct my interpretation of your code so it reads the way you want it to...

My updated version of your code
PHP Code:
if (isset($_POST['status'])) {
    
$query "SELECT MAX(Status) AS status FROM StatusTable WHERE Mapnumber = '$mapnumber'";
    
$rs mysql_query($query) or die(mysql_error());
    
$rowStatus mysql_fetch_row($rs);

    if (
$rowStatus['status'] > $status) {
        echo 
"The Status entered should not be less than '$rowStatus!'";
    }
} else {
    
$timestamp $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()); 


Try the code again... if you still get an error, or unexpected results, try telling us an example of the results and perhaps what they should be.

Reply With Quote
  #5  
Old October 18th, 2004, 10:39 PM
franches franches is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 franches User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i've had to change some of my codes and it worked. i've attached it here. but what i'm experiencing right now is that my form although does not insert the data in my database if the status is incorrect, it is subtracting the work hours entered from the default 7.5. And I was thinking what if the user logs out and decided to login again so the default should not be 7.5 anymore but the total remaining hours of that day. i don't know how to do it anymore.

any help will be great. thanks.
Attached Files
File Type: zip admin.zip (2.2 KB, 115 views)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > maximum Status


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT