dabaR
Members-
Posts
189 -
Joined
-
Last visited
Everything posted by dabaR
-
Cool, ya good luck. It is a fun way to think of code. You inherit the functionality by "extending" a class: class Files extends S3. But you don't want to inherit its functionality, you just want to use its functionality. That's different. A Dog "extends" (is an) Animal. A Person uses (also hopefully is not) a Tool. Hah, that joke totally crept in there.
-
OK, so what you have here is what is called a postback page. A page that has the GET version, which returns the HTML form to the browser...and you have the POST version, which is used to process the submission of that form. I commonly put all code that is meant to execute only when processing the form inside a if('POST' == $_SERVER['REQUEST_METHOD']) { ... } block. I see people often use if (isset($_POST['whatever_the_name_of_the_button_is'])){ ... } like you did. Don't you want to only check whether there are 8 things when the user is trying to post a new file?
-
Ya, you are definitely not doing inheritance, and not even composition. You are just using the S3 class as a library for now, think "Files class uses functionality provided by the S3 package". You might move into composition as your code evolves, but you are not likely to get into inheritance with this. <? if (!class_exists('S3')) require_once 'S3.php'; class Files{ public $bucket_contents; public $fileType; public $extraExtension; function __construct($accessVar, $keyVar, $bucket, $fileType, $extraExtension=null){ $s3 = new S3($accessVar, $keyVar); $bucket_contents = $s3->getBucket($bucket); $this->bucket_contents=$bucket_contents; $this->fileType=$fileType; $this->extraExtension=$extraExtension; } function listFiles(){ foreach ($this->bucket_contents as $file){ $fname = $file['name']; //gets the files with the extension we want if ( empty($this->extraExtension) ){ $ExtensionSplit = "."; }else{ $searchResult = stripos($fname, $this->extraExtension); if($searchResult){ $ExtensionSplit = $this->extraExtension . "."; } } if ( end( explode( $ExtensionSplit, $fname ) ) == $this->fileType ){ $furl = "http://s3.amazonaws.com/gmt.dvd.052110/".$fname; echo "<a href=\"$furl\">$fname</a><br />"; } } } } //$accessVar and $keyVar is populate with actual access and keys //this lists the files $files = new Files($accessVar, $keyVar, "gmt.dvd.052110", "zip", $searchExtraExtension = "mov" ); $files->listFiles(); What's your programming background, if you don't mind me asking?
-
Ugh, sounds like you would benefit by using a drupal installation with ubercart, I bet you they implemented all this, and have user points purchases extensions. Otherwise........ $has_enough_money = db_query("SELECT CASE WHEN users.money > items.price THEN 1 ELSE 0 END FROM users, items WHERE users.id = " . db_quote($user['id']) . " AND items.id = " . db_quote($item['id'])); This solution is a little bit conceptual, in that I am not 100% sure it would work, but give it a shot unless you decide to go the pre-built route.
-
I always say it is better to beat someone to the punch than it would be if you beat them with a punch. I think I made that up! I have my own silly quote! Pretty sweet.
-
Oh, OK. Nothing seemingly wrong with this piece, as far as I can see. Can you post the whole file? You could attach it to a post.
-
Try: date('Y-m-d', strtotime("$date + 365 days"));
-
At the time when the die() runs, are there more than 8 images in the directory you list on the top of the script?
-
This is the way subclassing is done, think "Files is a certain kind of S3, like a car is a certain type of vehicle": if (!class_exists('S3')) require_once 'S3.php'; class Files extends S3{ public $bucket_contents; public $fileType; public $extraExtension; function __construct($bucket_contents, $fileType, $extraExtension=null){ parent::__construct($bucket_contents, $fileType); } } //Outside of class ... $files = new files($accessVar, $keyVar); echo $files->someMethodOfS3Class(); You might be looking for composition, think "Files contains S3, like car contains engine": if (!class_exists('S3')) require_once 'S3.php'; class Files{ public $bucket_contents; public $fileType; public $extraExtension; public $s3; //or private? function __construct($bucket_contents, $fileType, $extraExtension=null){ $this->bucket_contents = $bucket_contents; $this->fileType = $fileType; $this->extraExtension = $extraExtension; $s3 = new S3($bucket_contents, $fileType); } } If you want more help from me, please show more of your code, and explain the algorithm you are trying to implement.
-
To me $data = $matches[1];[code=php:0] seems like a better way to express what you mean.
-
if this Array ( [0] => Array ( [0] => { if value>valuetwo } [1] => { do } ) [1] => Array ( [0] => if value>valuetwo [1] => do ) ) is an array called $matches, I think what you are looking for is already in $matches[1].
-
Ah OK, there, I learned something too. Thanks!
-
Please show the code, show sample data, and show what the result based on the sample data would be.
-
If I understand, you want to go through all the values inside brackets, right?
-
Thats what I had wrote originally but I thought it might be unstable, is this the case? . means any character * means zero or more of the preceding character ? means zero or one of the preceding character (character could be a set of characters, or whatever, a unit e.g. (blah)*, a*, [a-s]*...) So what is zero or one of zero or more of any character? I don't think it makes sense, but I could be missing something, that's why I asked if he knows what it really means. The problem with '{.*}' would be that .* can be a }, which is not what you want. You want to match opening brace, anything other than a closing brace, then a closing brace, so '{[^}]*}'.
-
What is '.*? '?
-
'/{([^}]+)}/' Maybe. I am not super good at it, but that should cover some of the cases. The tricky thing about regexes is that they are tricky to cover corner cases...what if...?
-
Here's this rewrite of the top part of your code to get your started reading: //This puts the current day, month, and year in seperate variables $day = date('d') ; $month = date('m') ; $year = date('Y') ; //Here we generate the first day of the month $first_day = date('Y-m-01'); //This gets us the month name $title = date('F') ; //Once we know what day of the week it falls on, we know how many blank days occure before it. If the first day of the week is a Sunday then it would be zero$blank = date('w', $first_day); //We then determine how many days are in the current month $days_in_month = date('t'); die(print_r(get_defined_vars(), true)); The last line will print out all defined variables to the screen so you can test that all the values are what they say they are.
-
Hi there. Please read this: http://www.phpfreaks.com/forums/index.php/topic,300076.msg1420283.html#msg1420283 , play with modifying it to your need a bit, and ask again for help when you get stuck.
-
OK, I did not feel like looking up the syntax for that monthname you are using, but I bet now that that is where your problem lies, so here it is: SELECT COUNT( leads.investor ) as total, COUNT(CASE WHEN MONTHNAME( FROM_UNIXTIME( leads.date ) ) = 'January' THEN 1 ELSE NULL END) AS jan , ... investors.first_name, investors.last_name, investors.investors_id FROM leads, investors WHERE YEAR( FROM_UNIXTIME( leads.date ) ) = '2010' AND leads.investor = investors.investors_id GROUP BY investors.investors_id LIMIT 0 , 30
-
Try this: 1. <?php function parseRSS($url) { 2. $feedeed = implode('', file($url)); 3. $parser = xml_parser_create(); 4. xml_parse_into_struct($parser, $feedeed, $valueals, $index); 5. xml_parser_free($parser); 6. foreach($valueals as $keyey => $valueal){ 7. if($valueal['type'] != 'cdata') { 8. $item[$keyey] = $valueal; 9. } 10. } 11. $i = 0; 12. foreach($item as $key => $value){ 13. if($value['type'] == 'open') { 14. $i++; 15. $itemame[$i] = $value['tag']; 16. } elseif($value['type'] == 'close') { 17. $feed = $values[$i]; 18. $item = $itemame[$i]; 19. $i--; 20. if(count($values[$i])>1){ 21. $values[$i][$item][] = $feed; 22. } else { 23. $values[$i][$item] = $feed; 24. } 25. } else { 26. $values[$i][$value['tag']] = $value['value']; 27. } 28. } 29. return $values[0]; 30. } 31. $xml = parseRSS("http://www.domain.com/category/feed/"); 32. foreach($xml['RSS']['CHANNEL']['ITEM'] as $item) { 33. $fDate = mb_substr ($item['PUBDATE'],5,11); 34. echo("<p>Latest update: <a href=\"{$item['LINK']}\">"); 35. echo($fDate); 36. echo("</a></p>"); 37. break; 38. } 39. ?> Not the cleanest solution by far, but it will likely work just fine.
-
There is a missing } on line 70!
-
Try... SELECT COUNT( leads.investor ) as total, COUNT(CASE WHEN MONTHNAME( FROM_UNIXTIME( leads.date ) = 'January' ) THEN 1 ELSE NULL END) AS jan , ... investors.first_name, investors.last_name, investors.investors_id FROM leads, investors WHERE YEAR( FROM_UNIXTIME( leads.date ) ) = '2010' AND leads.investor = investors.investors_id GROUP BY investors.investors_id LIMIT 0 , 30
-
Hi there! The only way that I can think of for that, if it could be done is using EXISTS. So something like this: SELECT * FROM table WHERE date = CURDATE() AND type = CASE WHEN EXISTS(SELECT * FROM table WHERE date = CURDATE() AND type = 'exception') THEN 'exception' ELSE 'default'; Maybe you should do the testing in the code, so something like: $exception_pricing = query('...'); if (!empty($exception_pricing)) { $normal_pricing = query('...'); } $pricing = empty($exception_pricing) ? $normal_pricing : $exception_pricing;