Jump to content

Jonob

Members
  • Posts

    77
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Jonob's Achievements

Member

Member (2/5)

0

Reputation

  1. I have a setup where users can store 'templates' in a table. When they add new products, they can apply these templates to the new product - basically it pre-fills fields in the product form. For example, they can store a template with a name of 'red tomato', and if they create a new product called 'red tomato', then the system will automatically find the rule, and apply the template. At the moment, this is super simple, and performed via a query as follows: SELECT * FROM (`templates`) WHERE `rule` like '%red tomato%' LIMIT 1 I'd like to take this to the next step, and give users more flexibility in how the search is performed. For example, I'd like to allow users to save wildcards with their template rules. So, they could create a template rule called '*tomato' and this would match any of the following search terms: 'tomato', 'red tomato' or 'green tomato'. Do I need to be careful with the wildcards that are allowed (reserved or special chars ?). Any other general concerns or comments would be appreciated.
  2. I am using a curl library to upload images to Amazon S3 using a php wrapper (http://undesigned.org.za/2007/10/22/amazon-s3-php-class). However, becuse CURLOPT_FOLLOWLOCATION is set to true on my server and open_basedir is enabled, this throws an error: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set I understand that I could disable open_basedir or use one of the workarounds at http://php.net/manual/en/function.curl-setopt.php. Instead, as a quick test I set CURLOPT_FOLLOWLOCATION = false. The image upload to S3 still seems to work, but I am concerned that something may break down the line. Are there any implications that I should be aware of? I am not quite if CURLOPT_FOLLOWLOCATION is it even relevant in this case?
  3. I have been familiarising myself with most of the well known frameworks. Codeigniter seems to come out trumps in terms of usability, ease of use and speed. However, my one major concern that sometimes gets repeated is that its a 'starter' framework and that developers tend to outgrow it. I am not quite sure what it means to outgrow a framework. Does anyone have real experience of this, and reasons why they moved from CI to something else (presumably Zend or Symphony?). I am looking to build a fairly large project, and want to make sure that over the long term is sustainable, maintainable and scalable (lots of ables!). Thanks for any advice that you can give.
  4. Howdy, I am running xampp on windows 7 64 bit and have one particularly intensive script to run. I have changed the max_execution_time var in /xampp/php/php.ini to 3000, and phpinfo clearly shows 3000 max_execution_time for local and master value. However, when running the script, I still get a "Maximum execution time of 60 seconds exceeded" error. Am I missing something obvious here? Thanks for any help you can provide.
  5. I have a database table that stores imported information. For simplicity, its something like: CREATE TABLE `data_import` ( `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `payee` VARCHAR(50) NULL DEFAULT NULL, PRIMARY KEY (`id`), INDEX `payee` (`payee`) ) I also have a table that stores import rules: CREATE TABLE `import_rules` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `search` VARCHAR(50) NULL DEFAULT NULL, PRIMARY KEY (`id`), INDEX `search` (`search`) ) The idea is that for each imported transaction, the query needs to try find a single matching rule - this match is done on the data_import.payee and import_rules.seach fields. There won't always be a match, and thats fine. Because these are both varchar fields, I have indexed them in the hope of making the query faster. This is what I have come up with so far, which seems to work fine. SELECT id.id, id.payee, ir.id, ir.search FROM import_data id LEFT JOIN import_rules ir on i.payee = ir.search I would like to now make this search functionality a little bit more powerful, so that a partial match can be returned. Lets say, for example, that we have id.payee = 'coca cola' and ir.search = 'cola'. This should still return a match. My understanding is that "LIKE '%search%'" has bad performance. Are there any other alternatives?
  6. Lets say that I have an array that I want to convert to a value object My value object class is as follows: /* file UserVO.php*/ class UserVO { public $id; public $email; public function __construct($data) { $this->id = (int)$data['id']; $this->email = $data['email']; } } And I create my array of value objects as follows: /* file UserService.php*/ $array = array( array(...), array(...)); $count = count($array); for ($i = 0; $i < $count; $i++) { $result[] = new UserVO($array[$i]); } return $result; OK, so this all works fine. However, I'd like to specificy the VO that is to be created dynamically, so that I can have a single dynamic function to create my VO's. Something like: $ret = create_vo($array, 'UserVO'); function create_vo($data, $vo) { $count = count($data); for ($i = 0; $i < $count; $i++) { $result[] = new $vo($array[$i]); //this obviously wont work...Class name must be a valid object or a string } return $result; } I realise that I could do this with a switch statement (iterating through all my VO's)...but there is no doubt a much much more elegant solution. It would also be supercool if I could lazy load the VO's as needed, instead of having multiple 'includes' Any help much appreciated.
  7. I am running a php script that: -queries a local database to retrieve an amount -executes a curl statement to update an external database with the amount + x -queries the local database again to insert a new row One of the problems that I am having is that if I have two different users from the same company running the same script at the same time, the execution time of the curl command (2-4 seconds), can cause a mismatch in what should be updated in the external database. This is the because the curl statement has not yet returned from the first user...so the second user is working off incorrect figures. I am not sure of the best options here. I thought of creating a field in the company table that records when a curl statement is being executed for that company - this flag is to prevent any simultaneous curl statements being executed until a response is received. The flag is automatically reset when a response from curl is received. If another user tries to execute the script then I could check to see if the flag is locked or not. If it is locked, then I could either: -Loop the the code and sleep for (5) seconds, and then check again if the flag has been reset. If after (3) loops, then reset the flag automatically (i've never seen the curl take longer than 5 seconds) and continue processing; OR -Just notify the second user that they should wait for (5) seconds before trying again. Are there any other (more elegant) ways of approaching this?
  8. Jonob

    Group by month

    My bad, seems like it needs to be: ... , SUM(CASE WHEN t.type_id = 1 THEN t.amount ELSE 0 END) as 'income' , SUM(CASE WHEN t.type_id = 2 THEN t.amount ELSE 0 END) as 'expenses' ...
  9. Hi all, I have a query that is grouping data by month and year: SELECT DATE_FORMAT(t.date_trans, '%b %Y') as date_trans , CASE WHEN t.type_id = 1 THEN SUM(t.amount) ELSE 0 END as 'income' , CASE WHEN t.type_id = 2 THEN SUM(t.amount) ELSE 0 END as 'expenses' FROM trans t GROUP BY DATE_FORMAT(t.utc_date_trans, '%b %Y') ORDER BY t.date_trans This works fine, but if I have type_id = 1 and type_id = 2 in the same month, then the query returns: date_trans | income | expenses Jan 2010 | 10 | 0 Jan 2010 | 0 | 5 Instead, what I need is: date_trans | income | expenses Jan 2010 | 10 | 5 Any help appreciated.
  10. I have a multi-dimensional array. Lets assume its something like: [0] [0] -> 'Green' [1] -> 'Soccer' [2] -> 'Oranges' [1] [0] -> 'Blue' [1] -> 'Rugby' [2] -> 'Apples' I want to remove the [2] index frome each sub-array, so that I land up with: [0] [0] -> 'Green' [1] -> 'Soccer' [1] [0] -> 'Blue' [1] -> 'Rugby' I can do this easily by looping through ...but is there an easier/faster way?
  11. Hi all, I am trying to resize an image using the following function. Everything appears to be working fine - I have verified that the correct size is obtained and that the correct $type is selected each time. The problem is that the resized_ image is not created at all. I'm probably missing something really obvious here....but I cant quite figure out whats going wrong. function resize_image($file) { $max_width = 350; $max_height = 100; //use php getimagesize function list($width, $height, $type) = getimagesize($file); if ($width > $max_width || $height > $max_height) { if($type == 1) { $image = imagecreatefromgif($file); } elseif ($type == 2) { $image = imagecreatefromjpeg($file); } elseif ($type == 3) { $image = imagecreatefrompng($file); } $resized_width = $width; $resized_height = $height; if ($resized_width > $max_width) { $aspect_ratio = $max_width / $resized_width; $resized_width = round($aspect_ratio * $resized_width); $resized_height = round($aspect_ratio * $resized_height); } if ($resized_height > $max_height) { $aspect_ratio = $max_height / $resized_height; $resized_width = round($aspect_ratio * $resized_width); $resized_height = round($aspect_ratio * $resized_height); } $resized_img = imagecreatetruecolor($resized_width, $resized_height); //resize the image imagecopyresized($resized_img, $image, 0, 0, 0, 0, $resized_width, $resized_height, $width, $height); if($type == 1) { imagegif ($resized_img, "resized_" . $file); } elseif ($type == 2) { imagejpeg ($resized_img, "resized_" . $file); } elseif ($type == 3) { imagepng ($resized_img, "resized_" . $file); } } }
  12. I have a query as follows: UPDATE customer SET account_id = account_id + 1 WHERE code = 1800 However, what I would like to do is update multiple lines, each with different criteria; something like: UPDATE customer SET account_id = account_id + 1 WHERE code = 1800 SET account_id = account_id + 2 WHERE code = 2000 SET account_id = account_id + 3 WHERE code = 2400 But this obviously wont work. Any ideas on the most efficient way to write this would be appreciated.
  13. Jonob

    Escaping text

    Thank you kickstart and Mchl - you have both been very helpful. $customer_type could indeed be a comma-delimited string, so explode, escape, add single quotes, implode worked perfectly.
  14. Jonob

    Escaping text

    Sure, the simplified version is something like: function get_customer($customer_type=null) { $sql = "SELECT id, name FROM customer"; $sql .= ($customer_type != null) ? " WHERE customer_type IN (" . mysql_real_escape_string($customer_type) . ")" : ''; //query database and return result, etc } The customer_type field in the customer table is a char(1) field. The values are not stored as (for example) 'J', but just as J (i.e. without inverted commas). The query doesnt work if its something like the following: SELECT id, name FROM customer WHERE customer_type IN (J) It does work if its like this: SELECT id, name FROM customer WHERE customer_type IN ('J') I need to escape the input, but as soon as I do that, it fails (as described previously)
×
×
  • 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.