Jump to content

deanes02

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by deanes02

  1. Thanks for the suggestion. The code runs without any errors but four character are still missing off the saved file. Each time I run it the new text goes in but another four characters are missing from the end. ???
  2. Thanks for your reply. Just one slight error $new_size = file_put_contents($filename, str_replace($search_for, $replace_term, $content)); should read $new_size = file_put_contents($filename, str_replace($search_for, $replace_term, $file)); Anyway with that fixed the output is Old file size was: 54635. New size is 54639. Expected size is: 54637. And there are two characters missing. If I run it again I get Old file size was: 54759. New size is 54763. Expected size is: 54761. and there are an extra four characters missing from the end!!!! This is the same why it worked with my code too. Any other ideas? I think its something to do with the fact that I'm trying to find "MJ" [including the inverted commas] and replacing with "AR" [including inverted commas]. The term is replaced twice in each instance. The inverted commas are the problem??? PLEASE HELP! Thanks...
  3. Hi, The following code atempts to open a text file, search for a term, replace that term with a new string, and resave the file. It all works fine except when the file is resaved four characters from the end of the file are deleted. I think this is because the file I open will be, say 1000 characters long, whereas the file I resave will ALWAYS be four characters longer, 1004. However only the first 1000 characters will be saved. Is there any way to save all the characters? As I said the code works perfectly other than that. I hope this all makes sense. Thanks! function void_case_statement($search_for,$replace_term,$filename){ $search_for = "\"$search_for\""; $replace_term = "\"$replace_term\""; //echo "debug $search_for,$replace_term,$filename<br>"; //read contents and add new text $fh = fopen($filename, 'r')or die("FAILURE : can't open file"); $content = fread( $fh, filesize( $filename ) ); fclose($fh); //echo $content; $new_content = str_replace($search_for,$replace_term,$content); //echo $new_content; //write new contents to file $fh = fopen($filename, 'w') or die("FAILURE : can't open file"); //echo $new_content; fwrite($fh, $new_content); fclose($fh); }
  4. Sorry about the delay in coming back to you. i tried the code and it worked perfectly. You guys are great!!! thanks!
  5. select * from mytable WHERE JobRef BETWEEN '2007-05-01' AND '2007-05-06' ORDER BY JobRef This is the statement I would like to use (or something similar). It is trying to find Jobs between two dates. The problem is the column JobRef is actually in the form AR2007-05-04 and EX2007-05-05 etc. Can I get the select statement to ignore the first 2 characters of the column (preferred)? Or do I have to create a new column with just the date and do the search on the date range on that (hopefully not)? Or some other solution? Thanks for your help, S
  6. My Apologies... this code actually does work. perfectly in fact! Once i cleared the cache in IE it all came good. thanks a million for your help.
  7. Thanks for your help so far. Below is my code and I've tacked on your bit to the bottom. Although the csv file is displayed nicely within IE no file, as far as I'm aware, has been created. I was expecting to be asked "Do you want to save this file?" or some such thing. I could save the page generated by the script through IE but thats not quite as slick as i was hoping to get. Am I missing something? Thanks, S //=================================set up query to search those tables $query = select * from wpctchie WHERE JobRef LIKE '%%' ORDER BY JobRef ; //echo "$query<br>"; $result = mysql_query($query,$connection) or die ("<b><font color='red'>Sorry. Could not execute your request this time. 6 </font></b>".mysql_error()); //display the field names for($i = 0;$i < mysql_num_fields($result);$i++) { $row = mysql_fetch_row($result); //echo mysql_field_name($result,$i).","; $csv .= mysql_field_name($result,$i).","; } //echo "\n"; $csv .= "\n"; //display the csv portion for ($i = 0; $i < mysql_num_rows($result); $i++) { $row = mysql_fetch_row($result); for($j = 0;$j<mysql_num_fields($result);$j++) { //echo $row[$j] . ","; $csv .= $row[$j] . ","; } //echo "\n"; $csv .= "\n"; } echo $csv; mysql_close($connection); // generate the file $p.="SalesOrderDB_". date("Y-m-d"). ".csv"; header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$p\""); header("Content-Transfer-Encoding: binary"); if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){ // IE cannot download from sessions without a cache header('Cache-Control: public'); } echo $csv; exit;
  8. Hi, I have done a lot of seraching on this and I can find code to create a server side copy of a csv file from MySQL. Although this doesn't work for me as access is denied to do this. What i want to do is with a button click download to contents of a table into a new local csv file (not adding the content to an existing file or anything). I know how to create the code to generate the csv from the MySQL [i.e. traverse the table adding commas at the end of each line and a return after the end of a line] but its the downloading and saving locally that i have difficulty with. Also if this download could happen automatically every night that would be a nice bonus. Sorry if I'm unclear. Please let me know. Thanks, S
  9. Thanks. The BIGINT is the solution. Simple when you know how! Thanks again
  10. This one is a bit annoying. I am inputting the integer "200706301725" into a MySQL DB. The field is set up to take int(12). If I put in that integer having 10 numbers then it records it fine in the DB. Once I go over 10 digits it records "4294967295". This number is the same no matter what 11 or 12 digit number i try to input. Am I missing something really simple here or what? Can MySQL only record 10 digits as an integer? Surely not. Any help is much appreciated. Thanks, Steve
  11. In phpinfo() I get session.gc_maxlifetime 1440 session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start. So i think that the system will automatically destroy sessions after 24 minutes (1440 seconds). Is this right? If so I'm totally sorted (I think!)
  12. Is there any way for me to find out how long an inactive session lasts on my (hosted) server before the session expires? If i set the timestamp to longer than that i'd be right in saying that User A would have been logged out by the server anyway before the lock was cleared - wouldn't I?
  13. thanks for your reply! I don't think solution 2 would work because the java timer would be client based and if the user simply closed the browser window this timer would be lost too resulting in the same problem. If i used this solution would the user not lose all of the data they were inputting on page refresh. The data would still be in the database but if the user was filling out the lengthy form the values would be lost - wouldn't they? Do you know of any way that I could code the following - if a user logs in a timer is set going on the server - if any row of the table has been locked for more than 15 minutes (or whatever) clear the lock?
  14. I have a MySQL database accessed by a php web interface. If one user is updating a row of the DB I want that row to be locked for all other users. The solution I came up with was to put in an extra column called 'lock_user'. When a user begins to edit a row the lock_user column for that row is filled with their login name (User A). If another user (User B) then tries to access the row he/she is told that the row is locked for editing by User A. When User A logs out the 'lock_user' column is cleared for that row and User B can then edit the row. So it all works very well IF User A logs out. However the problem is that if User A simply closes his browser window or leaves his session time out, the job is locked for all users because no command was sent to the DB to say clear the 'lock_user' column. I have created a command for the administrator to be able to clear the lock on any particular job but he is now getting annoyed with having to this all the time. Is there any way you can stop a user closing the web page with out having logged out first AND stopping their session timing out? OR (preferably) Is there any way you can automatically clear the contents of the 'lock_user' column when the browser window is closed or the session has timed out? OR Is there a better solution? Any help would be greatly appreciated. I can clarify anything as needs be. THANKS!
  15. I call an external function to execute the sql query - which it does successfully. The problem is that I want to then use the $result of the function to draw a table of results. If i put all the code together in one file the code works perfectly. If i have them seperated out like I do $result comes back as ==0 and "Error :" is printed to the screen but without any error nums or errors. How can I use the $result of an external function in my code? Many thanks to you all!! In "call function" file include("functions/SQLquery.php"); $query="select * from theTable"; sql_function($query); if($result == 0) { echo "<b>Error ".mysql_errno().": ".mysql_error(). "</b>"; } elseif (@mysql_num_rows($result) == 0) { echo("<b>Query completed. No results returned. </b><br>"); } else { echo "<table border='1'> <thead> <tr>"; for($i = 0;$i < mysql_num_fields($result);$i++) { echo "<th>".mysql_field_name($result,$i). "</th>"; } echo " </tr> </thead> <tbody>"; for ($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row = mysql_fetch_row($result); for($j = 0;$j<mysql_num_fields($result);$j++) { echo("<td>" . $row[$j] . "</td>"); } echo "</tr>"; } echo "</tbody> </table>"; } //end else In the "function file" function sql_function($passed_query) { /*Set up database variables*/ $host="xxx"; //obviously real values are put in here $user="xxx"; $password ="xxx"; $database = "xxx"; /*set up server connection*/ $connection = mysql_connect($host,$user,$password) or die ("<b><font color='red'>Sorry. Could not connect to the server this time.</font></b>"); /*set up database connection*/ $db = mysql_select_db($database,$connection) or die ("<b><font color='red'>Sorry. Could not connect to the database this time.</font></b>"); /*Set up the Query*/ $query = $passed_query; $result = mysql_query($query) or die ("<b><font color='red'>Sorry. Could not execute your query this time.</font></b>".mysql_error()); mysql_close($connection); }
×
×
  • 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.