Jump to content

JayDude

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by JayDude

  1. Thanx, but I still see each individual plant's total, what I need is to see only one line with the "KD..."s total hours combined ie the required output should be like the following: Total 493 Hrs
  2. Ok here is the query so far, and it works fine for one part of the report. Now I also need to "somehow" get the total accumalted hours from this query and this is where I get stuck, maybe there is a way within the query to get the result, then a trigger would not be required: SELECT`plant_id` , MIN(`plant_hrs_start`) min_hrs, MAX(`plant_hrs_stop`) max_hrs, (MAX(`plant_hrs_stop`)- MIN(`plant_hrs_start`) )total, `location_id` FROM`plant_hrs` WHERE MONTH(`plant_hrs_date`)= MONTH( CURRENT_DATE ) GROUP BY`plant_id` Outcome: plant_id min_hrs max_hrs total location_id ADT01 16909.0 16929.0 20.0 Middelkraal ADT07 28454.0 28510.0 56.0 Middelkraal DRZ14 4019.0 4120.0 101.0 Middelkraal EX06 5566.0 5816.0 250.0 Middelkraal KD01 12774.0 12956.0 182.0 Middelkraal KD03 16316.0 16335.0 19.0 Middelkraal KD04 14273.0 14455.0 182.0 Middelkraal KD06 16416.0 16495.0 79.0 Middelkraal KD07 1566.0 1597.0 31.0 Middelkraal As you can see the first part of my query works fine, but what if I need to state the TOTAL for only the "KD..."s which is 493 Hrs.
  3. I have a table for capturing machine hours. This includes start and stop hours. I am wondering if it is possible to add a third field to the table for "total", which auto-calculates the difference between the stop and start fields, after the first two fields have been entered? I know this can be done from a standard query, but if I can have a field already calculating each entry as I enter to go to the next line / entry, my queries will become substancially smaller and less difficult. ie (stop - start) = total {where total is a hidden field from the user and can not be entered manually} date machine_id start stop total 12/06/21 PCD123 2595.0 2601.3 6.3 query or formula should be within the table structure, is this possible?
  4. All my script is now working fine, but how do I fix the fact that some values will have a zero decimal and the user do not enter a decimal (ie 5269, the database should then enter the data as 5269.00) this minor issue asks me to correct the input. In other words, the user should not be forced to enter a value with a digit... if(!preg_match("~^[0-9]{1,10}\.[0-9]{1}$~",$value) )
  5. Thanks AyKay47, worked like a charm...
  6. I want to validate a form field for a number with two decimals (ie. 894567.29), but my script gives me an error, asking me to correct the entry, Following is a snippet of the script:- elseif($field == "oil_waste_ltr") { if(!preg_match("/^[0-9]{1,10}\.{2}$/",$value) ) { $bad_format[] = $field; } }
  7. Since I am a newby to php, I am certain that many pitfalls will be in my path - but a good heads-up is always welcome. I will use the info to concider speed over quality Thank you For now my problem is sorted, thanx
  8. Thank you very much for the feedback, I can deffinately see other advantages and uses for AJAX
  9. I have two basic dropdown lists in a form, my question is this: After selecting an item from the 1st dropdown list, the second dropdown list should automatically load only fields that are connected with the first selected item. (ex Site1 has Tank01 and Tank06, but Site2 has Tank03, Tank04 and also a Tank06). What is the script needed / or how do I change my script to accommodate this? Here is the basic script I use for the second dropdown list: <?php include("../xxx.php"); $cxn = mysqli_connect($host,$user,$password,$dbname); $query = "SELECT DISTINCT `diesel_tank_id` FROM `diesel_tank` ORDER BY `diesel_tank_id`"; $result = mysqli_query($cxn,$query); while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<option value='$diesel_tank_id'>$diesel_tank_id</option>\n"; } ?>
  10. CPD, Ignore my last post, it is working fine, thanks for the help... But I now have another question for you, maybe a bit more challenging. I have another dropdown list in the same form, script looks exactly like my first (and working fine) but this dropdown menu must only show items from the table corresponding with the first selected field. I have seen this in carsales websites so I know it can be done. Please help
  11. I tried that, but now my dropdown list gives an empty field with a blank dropdown list. Here is the snippet you gave me with the altered field:- (note I used ' ' else I get an error) { extract($row); $selected = ($plant_id == 'Blue' ? "selected='selected'" : ""); echo "<option value='$plant_id' {$selected}>$plant_id</option>\n"; }
  12. I created a drop-down menu using a MySQL statement in php for a form. My drop down menu works fine, but I want to assign a default value to it (normal text) the value will never change, thus I do not need to extract the default value from the table, I already know the value. Here is the basic snippet from the script: <?php include("../includes/xxx.php"); $cxn = mysqli_connect($host,$user,$password,$dbname); $query = "SELECT DISTINCT `plant_id` FROM `plant` ORDER BY `plant_id`"; $result = mysqli_query($cxn,$query); while($row = mysqli_fetch_assoc($result)) { extract($row); echo "<option value='$plant_id'>$plant_id</option>\n"; } ?>
  13. I just dont know what I'm doing wrong here, even copied your script snipped into the page, even deleted all non php script, so its only looking like the snippet you gave me, to no avail... Is there a way not to use a process page, but rather do it within the original form?
  14. still not working, here is the complete script from the process page: (error:404 web page not found) <?php if($_POST['display_button'] == "home page") { header("Location: http://www.ad181.co.za/home/test.htm"); // with the www } else { header("Location: http://ad181.co.za/insert/addDdr.php"); // without the www } ?>
  15. I have tried what you stated, but not one of the buttons point me in the right direction. Error Message: Website not found error:404 Here are the two headers: header("Location: ../home/test.htm"); //from public_html/home/test.htm and header("Location: addDdr.php"); //in the same folder as process file
  16. I am a newby using php as the backbone for my web design, with a help from phpFreeks, I have come along way in a short time. Below is a short script of two buttons created with php, how can I use the buttons to link to a new web page (similar to using "href" in html)? I would like to use the php created buttons to keep the general look and feel to my site the same through. In advance, thank you for the support... This is the part in my normal page that shows the buttons: echo "<form action='processButtonsDdr.php' method='POST'> <input type='submit' name='display_button' value='homepage' /> <input type='submit' name='display_button' value='new entry' /> This is a snippet from my two button process page: <?php if($_POST['display_button'] == "home page") { ????????????????? // what do I enter in this area to point the button to another webpage? } else { ????????????????? } ?>
  17. Thank you very much, changing the smallint(6) to an int(7) sorted my problem.
  18. Thank you all for your help. I found the answer, the incorrect entries that was recorder, were because the webpage back button was used to go back to the previous input form, thus the variable were kept in the $_POST and subsequently entered the data into the database. I will now have to create two exptra buttons on the output page, which tells the user "data successfuly recorded into the database." Namely, "make a nother entry" & "back to home page". Thank you for the interest, as a newby, I will probably make a lot of these mistakes along the way of becoming a pro... Jay Dude
  19. My php and MySQL scripting works perfectly, but when someone enters data into the php form, using an iPad with Safari browser, all number entries are inserted into the database table incorrectly. It is still a number entry but the number differs substantially from the original input. Note: All other entries, where the individual selects something from a drop-down list and date selecter works perfectly from the same form. Please help me here, since at least 70% of my employees use iPads, thus I need to find a cure for this problem ASAP. Thanks in advance for any help offered. JayDude
  20. I want to do an simple insert query, using a php form, insert a number reading. My problem is that when the database updates - the number that is entered differs substantially from what was entered in the form. The numbers can range from 1 to 99999: This is the table field that I have created (maybe the problem lies with the "smallint(6)") 3 diesel_dip_reading_value smallint(6) No None Following is a snipped of the php script: <p> <div class='field'> <label for='$diesel_dip_reading_value'>Dip Reading:</label> <input type='text' name='diesel_dip_reading_value' id='diesel_dip_reading_value' size='15' maxlength='15' /></div> </p>
  21. I am caught between a rock and a hard place here... My update page (to update an existing entity in the database) is a normal selection page, which then directs you to the page where you can update or change the data (1st srcipt snippet below), up to here everything works well, but on submit the page must be directed to a page that verifies the data (2nd script snippet below) and if correct, update the database or redirect to the 2nd page to correct the faulty data entry - easy right (well I have been struggling to get this working for 2 days straight. Pleeaaaaase Help. After the selection page, this is the input page-script:- $labels = array("company_descr" => "Description:"); include("../includes/xxxxxxxxx.inc"); // database login details $cxn = mysqli_connect($host,$user,$password,$dbname) or die ("Couldn't connect to server."); $query = "SELECT * FROM `company` WHERE `company_id`=\"{$_POST['comp']}\""; $result = mysqli_query($cxn,$query) or die ("Cannot execute query."); $row = mysqli_fetch_assoc($result); ?> <html> <head> <title>Update Location</title> <style type='text/css'> <!-- form { margin: 1.5em 0 0 0; padding: 0; } .field { padding-top: .5em; } label { font-weight: bold; float: left; margin-right: 1em; text-align: right; } #submit { margin-left: 20%; padding-top: 1em; } --> </style> <body> <?php echo "<div style='text-align: centre'> <h3>Update Company - \"{$_POST['comp']}\"</h3>\n"; echo "<p style='font-color: #FF0000; font-size: 12; font-align: center'> Please change the field(s) that you want to update below.</p> <hr /></div>\n"; echo "<form action='../update/updateCompany.php' method='POST'>"; foreach($labels as $field => $label) { echo "<div class='field'> <label for='$field'>$label</label> <input type='text' name='$field' id='$field' value='$row[$field]' size='35' maxlength='35' /></div>\n"; } echo "<div id='submit'><input type='submit' value='Update' />\n"; echo "</div>\n</form>\n</body>\n</html>"; ?> This is the script that is supposed to verify the data and then send you back to the input page or update the database if the data is correct foreach($_POST as $field => $value) { if(empty($value)) { $blanks[] = $field; } else { $good_data[$field] = strip_tags(trim($value)); } } if(isset($blanks)) { $message_2 = "The following fields are blank. Please enter the required information: "; foreach($blanks as $value) { $message_2 .="$value, "; } extract($good_data); include("../updateInput/updateInputCompanyTest.php"); exit(); } /* validate data */ foreach($_POST as $field => $value) { if(empty($value)) { if(preg_match("/descr/i",$field)) { if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/",$value)) { $errors[] = "$value is not a valid address or city."; } } } // end if not empty } foreach($_POST as $field => $value) { $$field = strip_tags(trim($value)); } if(@is_array($errors)) { $message_2 = ""; foreach($errors as $value) { $message_2 .= $value." Please try again<br />"; } include("../updateInput/updateInputCompanyTest.php"); exit(); } // end if errors are found else // add new member to database { include("../includes/xxxxxxxx.inc"); // database login details $cxn = mysqli_connect($host,$user,$password,$dbname) or die ("Couldn't connect to server."); $query = "INSERT INTO `company` (`company_descr`) VALUES ('$company_descr') WHERE `company_id`=\"{$_POST['comp']}\""; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); header("Location: ../backtomainpage.php"); } include("../updateInputCompanyTest.php"); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.