Jump to content

lindm

Members
  • Posts

    199
  • Joined

  • Last visited

    Never

Everything posted by lindm

  1. Yes two different submit buttons with the name/id goto1 and goto2.
  2. I have a form which should be submitted with either of two actions. Tried with javascript but this seems unreliable. Now looking at php and a processor page as the action of the form (process.php) which then sends the user to the different actionpages...can't figure out how to forward the post-variables to the different pages... Example process.php <?php if(array_key_exists('goto1', $_REQUEST)) { CODE FOR GOTO goto1.php } else if(array_key_exists('goto2', $_REQUEST)) { CODE FOR goto2.php } ?>
  3. Got a better solution now..is this the best that goes? function months($date,$date2){ $date3=strtotime($date); $date4=strtotime($date2); $date5=$date4-$date3; $date6=round($date5/86400/30); //days and then months print $date6; } months('2006-01-01','2007-04-30');
  4. Trying to build a function that gets the number of months between two dates (format YYYY-MM-DD). Here is my script so far: function months($date,$date2){ $date3=strtotime($date); $date4=strtotime($date2); $date5=$date4-$date3; $date6=floor($date5/31536000*12); print $date6+1; } months('2006-01-01','2006-02-14'); THis is not a consistent script...loose one month sometimes (for instance 2005-01-01 to 2005-12-31) which made me add (+1) month. This however affects for instance (2005-01-01 to 2005-01-02) which gives 1 month...HELP!
  5. I have the date as string in the format YYYY-MM-DD. Having problems finding a way to: 1. Add one day and remove one year (2006-12-31 would become 2006-01-01) 2. Remove -MM-DD (2006-12-31 would become 2006) 3. Only keep for instance 06 of 2006-12-31 Been looking at various date functions (http://se.php.net/manual/en/function.date.php) with no luck as well as str_replace...
  6. Got it now: $contents = file($_FILES['userfile']['name']);
  7. Is this correct? $contents = $_FILES['userfile']['name'];
  8. Hello again, What I am now trying is modifying my existing import script. I have (with help of course) created two functions that import data from an external file. What I am trying is to make the $contents (below) read the file that a user specifies in a separate form on a separate html page. In other words: 1. User is on form.html. User browses local drive and selects a file. 2. Form.html is submitted to import.php which contains the script below. $contents = file('file.txt'); foreach($contents as $line_value) { list($cat, $int, $id, $num) = explode("\t", $line_value); $cat = str_replace('#', '', $cat); $number[$cat][$int][$id] = trim($num); } //SIE FÖR ATT SUMMERA function calculate_range($cat, $bool, $range_min, $range_max) { global $number; $total = 0; for($i = $range_min; $i <= $range_max; $i++) { if(isset($number[$cat][$bool][$i])) { $total += $number[$cat][$bool][$i]; } } return $total; }
  9. Alrighty...as a newbie I need to find a way (function) to change the name of the file to for instance xxx.txt and if the file already exists replace the existing file.
  10. I am trying to create an upload script that performs the following: 1. Uploads to the file to the same directory as the upload.php script (right now it uploads to root it seems..) 2. Renames the file to xxx.txt (no function for this yet) 3. If xxx.txt exists it replaces this one (no function for this yet) 4. Limits import by file extensions (.se and .sie) (no function for this yet) Found some beginning code on the internet and here is my result so far: <?php $target = "/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 100000) { echo "Your file is too large.<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> Any help to complete much appreciated.
  11. Hello wildteen, Sorry for the delay, I have not been home for a few days. My testing shows that your solution functions very well. I will mark the thread as solved. Thanks for help all of you!
  12. wildteen88, Short followup question. Is there an easy way to create sums? FOr instance say I want to create a sum of $number['UB'][-1][1600] + $number['UB'][-1][1601] + $number['UB'][-1][1603] + up to $number['UB'][-1][1650]; How would I do this in an easy way? Thanks
  13. The last question is if the script is effective in executing, cache etc? That line is commented out. If you uncomment it it'll echo out the contents of the $number variable, which will display how the array is formatted. Not sure what you mean by this question:
  14. I need several identifiers and it was a tab so this is the code currently working. Thanks all!! Quick questions. Is this code ok from a memory perspective? Some of the text files can contain a lot of info. What is this part of the code? : //echo '<pre>' . print_r($number, true) . '</pre>'; Current code: <?PHP $contents = file('file.txt'); foreach($contents as $line_value) { list($cat, $int, $id, $num) = explode("\t", $line_value); $cat = str_replace('#', '', $cat); $number[$cat][$int][$id] = trim($num); } //echo '<pre>' . print_r($number, true) . '</pre>'; echo $number['UB'][-1][1650]*2;// returns -81219.00 // similarly $number['UB'][-1][1229]; will return 14100.00 ?>
  15. Looks like what I am after but the script (below) doesn't work. The php script and the file.txt in the same directory and I excuted the script...what am I doing wrong? <?PHP $contents = file('file.txt'); foreach($contents as $line_value) { list($cat, $int, $id, $num) = explode(' ', $line_value); $cat = str_replace('#', '', $cat); $number[$cat][$int][$id] = trim($num); } //echo '<pre>' . print_r($number, true) . '</pre>'; echo $number['IB'][0][2510]; // returns -81219.00 // similarly $number['UB'][-1][1229]; will return 14100.00 ?>
  16. Thanks for your paitience Is there some code like for sql? For instance get $row[2] where $row[1] ==1510? I want to be able to initiate a php function give it some variable ($row[1] == 1510 as an example) and it will return 246892.00.
  17. Sorry, will be a bit clearer...how do I for instance get the number 246892.00 from the text file below? ---file.txt----- #IB 0 2510 -81219.00 #IB 0 2640 495.37 #IB 0 2890 -43750.55 #IB 0 2990 -2300.00 #UB -1 1229 -4700.00 #UB 0 1229 -4700.00 #UB -1 1250 14100.00 #UB 0 1250 14100.00 #UB -1 1410 20000.00 #UB 0 1410 20000.00 #UB -1 1510 246892.00
  18. Ok here is my code so far for fgets...need some help to complete it...how do I get a certain data? <?PHP $file_handle = fopen("sie.txt", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('\t', $line_of_text); print $parts[0] . $parts[1]. "<BR>"; } fclose($file_handle); ?>
  19. It worked, just corrected a small ' missing after "$stringData .=". So it is not possible to have a single function for my problem that is called simply by '.function().' ? <?php $file = fopen("formsaved.html", "w") or exit("Unable to open file!"); function board() { return "test"; } $stringData = ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form" name="form" method="post" action="writeform.php"> <table width="610" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top">'; for ($num=1; $num<=10; $num++) $stringData .= board(); $stringData .= ' </tr> </table> </form> </body> </html> '; fwrite($file, $stringData); fclose($file); header("Location: formsaved.html"); ?>
  20. I believe the information is tab delimeted...does that facilitate things? I also now understand what -1 and 0 stands for...-1 is the value of previous year...this complicates it a bit more...I therefore now need to extract a number based on at least three conditions: 1. the line beginning with #IB, #UB or #RES 2. if the following controller i s0 or -1 3. the four digit following identifier (1220, 1299 etc) So a function with three variables perhaps? getdata($var1,$var2,$var3) Perhaps there is an easier way? I am just a beginner...
  21. Doesn't seem to go for me. Below is modified code: <?php $file = fopen("formsaved.html", "w") or exit("Unable to open file!"); function board() { return "test"; } $stringData = ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form" name="form" method="post" action="writeform.php"> <table width="610" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top">'.for ($num=1; $num<=10; $num++) echo board();}.'</td> </tr> </table> </form> </body> </html> ' ; fwrite($file, $stringData); fclose($file); header("Location: formsaved.html"); ?>
  22. Is it possible to execute a return function a certain times based on a variable containing a number. I don't want echo or anything so. This is my code that doesn't work: <?php $file = fopen("formsaved.html", "w") or exit("Unable to open file!"); function board($number) {for ($num=1; $num<=10; $num++ ) { return "test"; } } $stringData = ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form" name="form" method="post" action="writeform.php"> <table width="610" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top">'.board(5).'</td> </tr> </table> </form> </body> </html> ' ; fwrite($file, $stringData); fclose($file); header("Location: formsaved.html"); ?> In short. The above should return, $number of times...but doesn't per definition...any solutions? The reason I use return and not echo is becuase the above code is part of a variable containing html code to be written to a file...
  23. I have a text file (accounting information) which contains a lot of information and some of this information (numbers) I want to retreive (import to a php script) and be able to use some figures in calucations etc. Here is a piece of the text which shows the build up of the information I want to use: ----text file excerpt---- #IB 0 2099 -226930.95 #IB 0 2510 -81219.00 #UB 0 2641 1114.28 #UB 0 2645 6978.00 #UB -1 2890 -43750.55 #RES 0 5800 46239.60 #RES -1 5900 574.92 #RES 0 5900 6402.63 ----end---- The identifier is the column containing 2099, 2510, 2641 etc. So for example in a php file a function (extract for example) will open the text file and extract the number to the right based on the identifier column. Php example (extract(2099) + extraxt(2641)) will result in: -225816,67 Any help much appreciated.
×
×
  • 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.