Jump to content

VTS

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Everything posted by VTS

  1. Well this function I created is supposed to read the data from a file into my database, but for some reason that I cannot see, it is stuck in an eternal loop.  it seems to go back to the beginning of the else statement everytime.  So when I use this function, it cycles through all of the rows and once it hits the last line it seems to go back to the beginning of the else statement and just do the whole process over and over again until I hit the stop button.  I hope that this is written clearly enough for everyone to understand.  If you don't understand what I am talking about, I will try to clear it up. Here is my code: [code]<?php function read_fms_file($date){ $sql = "DELETE FROM payroll_dept_totals         WHERE pdt_date = '$date'"; run_sql($sql) or die(mysql_error()); $file = "c:\\fms_data\\$date\sales_to_labor.txt"; if(!file_exists($file)) {   $_SESSION['message'] = "File does not exist";   return false; } else{   $handle = fopen($file, "r");   $contents = fread($handle, filesize($file));   fclose($handle);   $row = explode("\n", $contents);   $rows = count($row);   echo "1 ";   $i = 0;   //for($i = 0; $i < $rows-1; $i++) {   while($i < $rows-1){   $parts = explode(" ", $row[$i]);   echo "2 ";   unset($numbers);   $numbers = array();   foreach($parts as $part) {     $part = trim($part);     if(is_numeric($part)) {     //echo "part = ".$part."|";     echo"3 "; array_push($numbers, $part); }   }   echo "numbers = ".$numbers."    ";   array_pop($numbers);   array_pop($numbers);   echo "4 ";   $sql = "INSERT INTO payroll_dept_totals (pdt_store_id, pdt_dept_id,                         pdt_oper_wages, pdt_oper_hours, pdt_ben_wages, pdt_ben_hours, pdt_date)       VALUES (";   foreach($numbers as $number) {     $sql .= "'$number',";     echo "5 ";     echo "5 ";     //echo "number = ".$number."    ";   }   echo "6 ";   echo "row = ".$i." ";   $sql .= "'$date')";   $result = run_sql($sql) or die(mysql_error());   $i++;   }   //return true; } } ?>[/code] sorry if the code is a little messy. Thanks in advance for any help!!
  2. Thanks alot wildbug!! I will add that in now. Thanks for explaining the code tag thing too. I didn't know that.
  3. Thanks alot wildteen!!! I will get right on this after lunch. This stuff would take me forever to learn...I just looked up some stuff on regex and it seems to be something that would take awhile. Thanks again for all the help!!
  4. Ok, I need to remove whitespace from a text file that I have. I found an expression that will remove the space from the beginning and the end of a string but I need it to change the spaces between my columns in the text file from many spaces to one in addition to removing the spaces before and after the line. Here is an example of what I want it to do: edit** for some reason I cannot put the numbers in the format that they are in the text file. they would have some spaces before the first column then anywhere from 1-9 spaces between the columns. I would like them to have no spaces before the first column or after the last and one space between columns like this: 12 3 4 3 4 1 2 34 1 23 111 Thanks in advance for any help I apologize in advance for any stupid questions I ask because I have never used regex before.
  5. Thanks for not giving up on me here.....once I get this figured out, I should be good to go. By the way, what is regex?
  6. Yup they are before the first column and also the spaces between the columns are different (anywhere from 1-9). Thanks again for the help!! I will try that out now and see how that works.
  7. Well I found out that it won't read the data in correctly when there is more than one space between the rows in the file that I am reading. So my next question is how can I go about fixing this without having to have to manually delete spaces.
  8. Well I got it all written now but for some reason the data that gets entered into the database is all zeroes except for one field. Would the spacing in the file I am reading from have anything to do with this? Some of the fields have 5 spaces between them, others have more or less. Also, there are about 5-8 spaces between the leftmost column and the left margin in the file. I opened up the file it was reading from just to make sure it has data in it, and it does so I am not quite sure what would cause the date that gets read in to be all zeroes. Also, is there a size limit on how big the file can be that I am trying to read from? The file is 31kb.
  9. Wow!! That is great! Thanks alot for all the help and the quick replies. I just want to say that this is by far the best forum for php that I have ever come across. Thanks again, VTS
  10. Ok, I have looked up how the functions work but I am still a little confused on how I am going to get the data stored into an array. If the data looks like this: 23 42.00 24 29 20.00 3 34 78.00 5 Column 1 being the item id, column2 being the price, and column 3 being the quantity. How will I get this data stored as such? Sorry, this is the first time I have ever tried to read data from a file into a database so I am still having a rough time with it.
  11. VTS

    Copying a file

    Hmm...well I guess that kinda kills javascript. I guess I will have to try to use the workaround that jvrothjr uses unless you have any suggestions. Thanks for the replies guys.
  12. VTS

    Copying a file

    Thanks for the help once again jvrothjr! I think If possible I will try the javascript but if that doesnt work out, I will consider what you use as a workaround. [!--quoteo(post=386970:date=Jun 22 2006, 03:30 PM:name=Eric_Ryk)--][div class=\'quotetop\']QUOTE(Eric_Ryk @ Jun 22 2006, 03:30 PM) [snapback]386970[/snapback][/div][div class=\'quotemain\'][!--quotec--] How exactly would you plan to use javascript to copy a file? I think you are overestimating its ability. [/quote] Well I found a script when I was looking on google that is supposed to use javascript to copy a file from one location to another. This was what I found: [code]<!-- myActiveXObject = new ActiveXObject("Scripting.FileSystemObject"); file = myActiveXObject.GetFile("c:\\test.txt"); file.copy("d:\\test.txt", true); // -->[/code]
  13. VTS

    Copying a file

    Thanks for the info and yes, I am using apache. So I guess this means that I have to use the javascript then. Anyone know how to imbed that into my php?
  14. I have been trying to copy a file using php but for some reason, I cannot copy a file from a drive on the network to my c drive using the copy function. I can copy files from one place on my c: to another place on my c: but as soon as I try to copy a file from a network drive it tells me the file does not exist. The only thing I could think to do was to find a workaround for this by using javascript to copy the file to my c: so I can use it. The problem I have is that I dont know how to imbed javascript into my php. If anyone could give me some ideas on how to fix the problem with not being able to copy from a network drive or how to imbed javascript into my php I would greatly appreciate it.
  15. Thanks alot wildteen, that helps out alot. I should be able to figure it out from here.
  16. How would I go about reading data into a database from a text tile? The format would be similar to this: 23 343.03 23 24 43.56 19 Where the first column would be an id number, the second would be a total price, and the third would be how many of that item were sold. I am pretty new to php and I am not quite sure how to go about this. Anyone have any ideas on how to do this or where I can look to learn about it?
  17. Thanks for the quick response SemiApocalyptic!
  18. I looked on php.net at the manual but I didnt find the answer to my question. I was wondering how I would go about copying a file from something like "c:\php stuff\php documents" to another destination. Obviously, you input the source and destination in the function but I am wondering about the spaces in the directory. Will it handle it the same as it would "c:\php_stuff\php_documents"? Any help would be greatly appreciated
  19. Sorry if this is the wrong place for this, but I am looking for help with a program to send an email. What I wasnt it to do is send an email to me anytime that another program i have written gets an error. For example: if someone logs on and uses my program but it cannot read any data from the database, I would like to get an email notifying me of the error. I would like to know where I can look to find some info on this. Any help is greatly appreciated.
  20. Well I changed the if statement but I still cant seem to get it to display anything....I have checked to make sure that all of the data is stored in the database and it is. So I guess I am still stumped.
  21. I have most of the program done for making a forum with php. The problem that I am running into is with a program that shows the posts in a topic. When I click on a topic, it displays a blank page. Any help would be greatly appreciated. here is the code from the prog that shows the posts in a topic: <?php /** * A script that shows the posts in a topic * * @version $Id$ * @copyright 2006 */ // check for required info from the query string if (!isset($_GET['topic_id'])) { header("Location: topiclist.php"); exit; } // connect to server and select database $conn = mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("testDB", $conn) or die(mysql_error()); // verify that the topic exists $verify_topic = "select topic_title from forum_topics where topic_id = $_GET[topic_id]"; $verify_topic_res = mysql_query($verify_topic, $conn) or die(mysql_error()); if (mysql_num_rows($verify_topic_res) < 1) { $display_block = "<p><em>You have selected an invalid topic. Please <a href=\"topiclist.php\">try again</a>.</em></p>"; } else { // get topic title $topic_title = stripslashes(mysql_result($verify_topic_res, 0, 'topic_title')); // gather the posts $get_posts = "select post_id, topic_id, post_text, date_format(post_create_time, '%b %e %y at %r') as fmt_post_create_time, post_owner from `forum_posts` where topic_id = $_GET[topic_id] order by post_create_time asc"; $get_posts_res = mysql_query($get_posts, $conn) or die(mysql_error()); $sql = "SELECT topic_id, post_text FROM forum_posts WHERE topic_id = $_GET[topic_id]"; $result = mysql_query($sql, $conn) or die(mysql_error()); while ($array = mysql_fetch_array($result)) { echo "Text for the topic: " . $array['post_text'] . "<br />"; } // create the display string $display_block = " <p>Showing posts for the <strong>$topic_title</strong> topic:</p> <table width=100% cellpadding=3 cellspacing=1 border=1> <tr> <th>Author</th> <th>POST</th> </tr>"; while ($posts_info = mysql_fetch_array($get_posts_res)) { $post_id = $posts_info['post_id']; $post_text = n12br(stripslashes($posts_info['post_text'])); $post_create_time = $posts_info['fmt_post_create_time']; $post_owner = stripslashes($posts_info['post_owner']); // add to display $display_block .= " <tr> <td width=35% valign=top>$post_owner<br>$fmt_post_create_time</td> <td width=65% valign=top>$post_text<br><br> <a href=\"replytopost.php?post_id=$post_id;\"><strong>REPLY TO POST</strong></a></td> </tr>"; } // while // close up the table $display_block .= "</table>"; } //end else ?> <html> <head> <title>Posts in Topic</title> </head> <body> <h1>Posts in Topic</h1> <?php print $display_block; ?> <p><a href="topiclist.php">Click Here</a> to go back to the main topic page</p> </body> </html>
×
×
  • 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.