Jump to content

jetsettt

Members
  • Posts

    38
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

jetsettt's Achievements

Member

Member (2/5)

0

Reputation

  1. Yes Batwimp. Working great thanks to you. I was stuck for a few hours and your help has got me going again. Thankyou very much. This forum is great.
  2. Thanks very much. I added $dir to the code that you re-write for me. From.. if(filemtime($file) >= strtotime('2010-04-12')) to.. if(filemtime($dir.$file) >= strtotime('2010-04-12')) The path is now correct to read the timestamp of the files.
  3. Got it setup on a test file and directory. It works with '.' set as the path but not 'imgs/' set as a path (contains a small number of .jpgs) Can't figure why it won't work with a path other than root set?
  4. I saw the $path variable needed changing. I'm not getting any output. I do trust the code is good but can't seen to get it working. I have put it in place where the old code was.
  5. Thank you very much Batwimp for your help. I see what you mean with the timestamp check. I'm unable to get the code working but I'll have a go at getting it to work. Your help is very much appreciated.
  6. Hi all, I have a PHP function that reads JPG's from a folder that contains over 100,000 files. The problem I have is that the READDIR() function takes a while to list the contents due to the large number of files. I'm trying to speed up the process by using a filter and listing only the files I need. Example: list files with a timestamp for an entered date period. $file >= '2012-04-02 OR $file <= '2012-03-04' This lists the JPG files but my modification to list files using a timestamp does not work nor can I find a way of seeing why it does not work. This has me stuck. Thank you in advance to anyone who can post some pointers. Code that lists JPGS only <?php $path = 'imgs/'; function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} // 'all' filter is if you set to list ALL files and folders. if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle))!==false) { for ($f=0; $f < sizeof($filters); $f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } $files = directory($path, "jpg"); //for multiple file types just separate the file extensions by commas foreach ($files as $value) { echo $value.'<br>'; } ?> I have added the filter && filemtime($file) >= strtotime('2010-04-12') but it does not work. <?php $path = 'imgs/'; function directory($dir,$filters) { $handle=opendir($dir); $files=array(); if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}} // 'all' filter is if you set to list ALL files and folders. if ($filters != "all") { $filters=explode(",",$filters); while (($file = readdir($handle) && filemtime($file) >= strtotime('2010-04-12'))!==false) { for ($f=0; $f < sizeof($filters); $f++): $system=explode(".",$file); if ($system[1] == $filters[$f]){$files[] = $file;} endfor; } } closedir($handle); return $files; } $files = directory($path, "jpg"); //for multiple file types just separate the file extensions by commas foreach ($files as $value) { echo $value.'<br>'; } ?>
  7. I have finally sorted this. I could kick myself. All that was need was the adding of the database name to the query. I had two DB connections and mysql_query() would choose to either run or not on each page load. By setting the full DATABASE.TABLE info for the INSERT query ensured that mysql_query() works every time as it knows exactly which DB to insert to. I changed the code from... $query="INSERT INTO `sms` (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`) VALUES $values"; to... $query="INSERT INTO smsdatabase1.sms (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`) VALUES $values"; Thanks to Pyscho who put me on the right road with the diagnostic code. $result = mysql_query($query, $sms_db) or die ("Query failed: " . mysql_error() . " Actual query: " . $query); mysql_error() showed me that it could not find the DB. It was then possible to quickly identify the problem with the code.
  8. I am checking for the error and the error seems to occur when the INSERT query is ran at $result=mysql_query($query, $sms_db); The code that assembles the data ready for the INSERT works everytime and collects the data. $query="INSERT INTO `sms` (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`,`sms_type`, `sms_processed`) VALUES $values".";"; ... it just does not insert everytime when the query is run. The debugging code you posted does not seem to check if the INSERT completes successfully, which is my problem. The last bit of code I pasted was a pasting mistake, sorry for the confusion. It should not have had two instances of mysql_query() $result = mysql_query($query) or die(mysql_error()); $result=mysql_query($query, $sms_db); // Run the query There is a unique, incrementing field in the table (sms_id). The sms_unique field in the query is only used for unique url calling, so should not cause any DB inserting problems. Thanks for your help, I appreciate it but I don't think this is going anywhere. I have tried to explain though.
  9. I am coming to that conclusion because if I echo $result=mysql_query($query, $sms_db); it is not outputting '1' as expected if it works. Nothing is output when it fails. ini_set('display_errors',1); error_reporting(-1); Is outputting... Warning: mysql_free_result(): 48 is not a valid MySQL result resource in /home/site.test/public_html/sms_sending_complete.php on line 236
  10. I have indeed FAILED!. I missed the code that you put and I have now seen and included it, thank you. Here is the output which points to the insert query as not completing. Attempting to create Array records. Records successfully created: 3 Query ran: INSERT INTO `sms` (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`) VALUES ('skft2pzzrdxapfz63l1z6hj6rs00rova','2012-03-05 18:32:45','TEST MESSAGE!','440000000000','sent','2012-03-05 18:32:45','1753'),('c0fb1srn4amcpv4mwnpy4y141wpx3nm5','2012-03-05 18:32:45','TEST MESSAGE!','440000000000','sent','2012-03-05 18:32:45','1753'),('aymueugqagdsccy6h2gnso11mlm3mg5k','2012-03-05 18:32:45','TEST MESSAGE!','440000000000','sent','2012-03-05 18:32:45','1753');
  11. When I echo the output everything looks good apart from the final query code. echo $result=mysql_query($query, $sms_db); I should get '1' for a completed INSERT query but it sometime returns nothing. I don't know what else to do?
  12. There is no debugging output apart from the fact that the insert does not complete intermittently. Nothing changes on the page. What else can I look out for?
  13. Thanks for your reply, appreciated. The for() loop should have the opening bracket in the code below. The whole function does work as intended (I have included more code to make it all clearer). The problem is that the records are not alway inserted. It is intermittent. I re-submit the page and it works or fails ?!?! I am starting to think that it is an issue with MySQL. I am running version 5.0.75 on Ubuntu server 9.04. Heres more of the code. <?php // Function to generate a random string for each entry function makeRandomstring() { $salt = "abcdefghijklmnopqrstuvwxyz0123456789"; srand((double)microtime()*1000000); $i = 0; while ($i <= 31) { $num = rand() % 33; $tmp = substr($salt, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } $stripped_message = ereg_replace("[^A-Za-z0-9 #!?£$*%&.(){}@;:,=+<>_/-]", "", $_POST['message']); // only allow certain sms valid chars $userid = $_SESSION['kt_login_id']; // user // Set $selected as -0 if null so db query does not break. If there is a value continue. $selected = "-0"; if (isset($_POST['recipient'])) { $selected = $_POST['recipient']; } if (is_array($selected)){ // If $selected is an array continue with adding quotes foreach($selected as $selected_quoted) { $quoted[] = '\''.$selected_quoted.'\''; // loop and encapsulate in single quotes to work with the IN() function. } $selected = implode(",", $quoted); // implode it as a comma seperated string eg 23,34,39 } else { $selected = $selected; // no array -> print single value } mysql_select_db($database_scheme, $scheme); $query_selected_recipients = "SELECT Users.User_mobile, Users.User_first_name, Users.User_last_name, Users.User_level, Users.User_random_key FROM Users WHERE Users.User_random_key IN ($selected) AND Users.User_mobile REGEXP '^[0-9]{11}$' ORDER BY Users.User_last_name ASC"; $selected_recipients = mysql_query($query_selected_recipients, $scheme) or die(mysql_error()); $row_selected_recipients = mysql_fetch_assoc($selected_recipients); $totalRows_selected_recipients = mysql_num_rows($selected_recipients); $date = date('Y-m-d H:i:s'); for ($i=0; $i<count($_POST['recipient']); $i++) // loop based on count of selected users { $uk_mob_number = "44".substr($row_selected_recipients['User_mobile'], 1); // take off the first digit and replace with 44 $unique = makeRandomstring(); // Create a unique string for each entry $values.="('$unique', '$date', '$stripped_message', '$uk_mob_number', 'sent', '$date', '$userid'),"; } // End of loop $values=substr($values, 0, -1); // to remove last comma $query="INSERT INTO `sms` (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`) VALUES $values"; $result = mysql_query($query) or die(mysql_error()); $result=mysql_query($query, $sms_db); // Run the query ?>
  14. Can anyone help me out with this. I have been struggling on and off it for weeks. Heres the description of the problem. I insert into a MySQL database from a query that is performed using an array that is posted from a page. The incoming array contains selected users (unique id's) that are used to lookup the users telephone numbers in a query and then insert into a DB. This code works intermittently. It will insert the records fine and then on the next attempt it may not? There is not pattern to it working and failing. Does anyone have any idea why this is happening? I have tried a loop using the posted array data count and also a loop based on the count of records brought back from the query but to no avail, it is still intermittently working. The '$stripped_message' data is just a text string. <?php $date = date('Y-m-d H:i:s'); for ($i=0;$i<count($_POST['recipient']);$i++) // loop based on count of selected users $uk_mob_number = "44".substr($row_selected_recipients['User_mobile'], 1); // take off the first digit and replace with 44 $unique = makeRandomstring(); // Create a unique string for each entry $values.="('$unique','$date','$stripped_message','$uk_mob_number','sent','$date','$userid'),"; // usleep(50000); // Tried a delay to try to fix, did not work } // End of loop $values=substr($values,0,-1); // to remove last comma $query="INSERT INTO `sms` (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`) VALUES $values".";"; ?>
  15. Thanks for that, it works fantastic. The error has gone and this executes quickly. SELECT u.User_email, lt.last_time AS last_signed_in, r.last_time AS reminder FROM Users u LEFT JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 3 GROUP BY User_id ) lt ON u.User_id = lt.User_id LEFT JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 12 GROUP BY User_id ) r ON u.User_id = r.User_id I had to change 'User_id' to 'log_usr' to get it to work. SELECT u.User_email, lt.last_time AS last_signed_in, r.last_time AS reminder FROM Users u LEFT JOIN ( SELECT log_usr, MAX(log_time) AS last_time FROM log01 WHERE log_type = 3 GROUP BY log_usr ) lt ON u.User_id = lt.log_usr LEFT JOIN ( SELECT log_usr, MAX(log_time) AS last_time FROM log01 WHERE log_type = 12 GROUP BY log_usr ) r ON u.User_id = r.log_usr I will go and study this now to understand how it works. Thanks very much juddster !
×
×
  • 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.