|
I hope someone can help me with this or point me in the right direction. I'm looking for a range function. (I'm not sure if Range is the right word.) I'd like to search a value between certain numbers. Basically, I'd like to do this... If TOTAL is between 1-10, ANSWER is "10 bucks" IF TOTAL is between 11-20, ANSWER is "20 bucks" IF TOTAL is between 21-30, ANSWER is "30 bucks" and so forth. Any help is appreciated, or just the function I can look up. Thanks.
|
# ? Nov 21, 2012 06:02 |
|
|
# ? Jun 1, 2024 08:52 |
|
You could just do ceil(x/10) * 10 where x is your total.
|
# ? Nov 21, 2012 06:13 |
|
Does anyone know of a PHP application or a SaaS that would work for a photographer to upload images to the Internet for customers to order prints or a digital download. I know there are places like smugmug that do this, but the company looking for this service actually does their own printing, photo mugs, books and anything else you can put a picture on. They really just need a way to offer digital downloads of the original images in addition to the items they already sell online. This is a bit more advanced than any open source gallery products I'm familiar with and am hoping some of you might have seen or worked with something that will work for them. DarkLotus fucked around with this message at 16:58 on Nov 21, 2012 |
# ? Nov 21, 2012 16:56 |
|
I am using the stock, out-of-the-package PayPal Access solution offered by PayPal (please see here: https://www.x.com/developers/paypal/documentation-tools/quick-start-guides/oauth-openid-connect-integration-paypal). Near the bottom of that page, there is a list of attributes. There is one attribute that I need that is NOT listed. You might conclude, "Well, then, it's impossible" ... but you'd be wrong. If you're interested, then please go here and login using PayPal Access (either button): http://identity.jakub.me/ in order to see what I'm talking about. Near the bottom of the the list of response data (the attributes provided by identity.jakub.me site), you'll see one not listed by PayPal called "PayerID" It's provided by the resource at: https://www.paypal.com/webapps/auth/schema/payerID ************ I NEED someone to take whatever portion of the code from identity.jakub.me (found here: https://github.com/jakub/paypal-access-demo) that is getting payerID and incorporate it into the stock, out-of-the-package PayPal Access solution offered by PayPal (please see here: https://github.com/paypal/paypal-access/tree/master/openid-connect-php-ppaccess) Anyone interested?? I'm willing to pay!
|
# ? Nov 23, 2012 03:41 |
|
It looks like identity.jakub.me is doing all the hard work with the attribute exchange OpenID extension. You'd most likely you'd need to implement a lot of the OpenID, extension and attribute exchange code, and by that point you might just be better off using the jakub code anyway. It's using the details from https://www.x.com/developers/community/blogs/itickr/paypal-openid-implementation-details for it's list of supported attributes.
|
# ? Nov 23, 2012 05:42 |
|
The Gripper posted:It looks like identity.jakub.me is doing all the hard work with the attribute exchange OpenID extension. You'd most likely you'd need to implement a lot of the OpenID, extension and attribute exchange code, and by that point you might just be better off using the jakub code anyway. Ya, good call ... I didn't connect two and two that they were using the old OpenID protocol. It looks like the /payerID/ resource still provides PayerID but, interestingly, PayPal no longer lists it as one of the available attributes at that URL you provided. So frustrating ... I've contacted PayPal, and they agree that payerID *SHOULD* be included --- they couldn't determine why it was removed and have put in a feature request .... but that process could take many months. The objective of PayPal Access is to simplify sign-up and sign-in, but as currently implemented, they're not providing a unique user attribute that is guaranteed to remain constant between a user's logins (last name, first name, account creation date, etc. are not unique enough to determine whether the incoming user is new or simply returning, and email address - which would be unique enough - can be changed). As a result, PayPal Access does not provide a data point to check in order to determine if an incoming user already exists in a user database. So, if between visits to my site, a user changes their email, then - when they re-visit my site - the site will think they're a new user. Gr.....
|
# ? Nov 23, 2012 15:42 |
|
tridens posted:ustrating ... I've contacted PayPal, and they agree that payerID *SHOULD* be included --- they couldn't determine why it was removed and have put in a feature request .... but that process could take many months. The whole Paypal Access platform is lovely to work with, I don't even think they offer a developer sandbox like they do with other methods so it's obnoxiously difficult to even do any prototyping with.
|
# ? Nov 23, 2012 16:05 |
|
The Gripper posted:I doubt they'll ever provide it since it looks like they're focused on fields that have a schema provided by OpenID itself, which payerID isn't covered by. I sure hope you're wrong. They are offering: Age Range: https://uri.paypal.com/services/paypalattributes Account Type: https://uri.paypal.com/services/paypalattributes Account Verified: https://uri.paypal.com/services/paypalattributes Account Creation Date: https://uri.paypal.com/services/paypalattributes via the OpenID Connect protocol (see: https://www.x.com/developers/paypal/documentation-tools/quick-start-guides/oauth-openid-connect-integration-paypal) That was my argument for getting them to offer PayerID ... why all this other jazz and not something as harmless and USEFUL as PayerID? That's where they agreed with me. I'm just going to have to wait ... I'm not nearly strong enough with php to figure out how to incorporate the bits and pieces of OpenID into my current usage.
|
# ? Nov 23, 2012 16:36 |
|
Huh, I never noticed that those were included before as part of the regular set. It's odd then that they wouldn't include payerID considering it's available through other means with OpenID, in that case.
|
# ? Nov 23, 2012 17:00 |
|
The Gripper posted:Huh, I never noticed that those were included before as part of the regular set. It's odd then that they wouldn't include payerID considering it's available through other means with OpenID, in that case. Exactly! If you have an account, I'd appreciate a vote: https://www.x.com/developers/paypal/forums/paypal-access/vote-include-payerid-list-attributes-provided-paypal-access Pretty inconsequential ... but it's about all I can do now besides wait on the feature request to get action Edit: I managed to get in touch with a senior developer on the PayPal Access team and he agrees that it should be offered; he's going to discuss it with the rest of the team on Monday. Keep your fingers crossed. Edit2: To their infinite credit, the PayPal team agreed that the payerID attribute needs to be added and are actively working to include it in the PayPal Access OpenID Connect flow. Very impressive to see a big company manage to remain so responsive. tridens fucked around with this message at 04:31 on Dec 4, 2012 |
# ? Nov 23, 2012 19:57 |
|
So I'm putting in some volunteer hours at a local coop, gonna help a little with their website. They want to be able to upload their prices from their Point of Sale to the website. It outputs CSV, and while PHP isn't really a language I've done much with I don't see myself having any trouble parsing and outputting that stuff. My question is more about using the right way to allow the guys there to upload the file using Drupal's Access Control. I figure once I have an easy way for them to get the file on the server, on the public page all I'll need to do is get and process that file on demand with a level of caching. Any suggestions on the approach?
|
# ? Nov 27, 2012 23:32 |
|
Any help is appreciated with this. I'm just not good with php and arrays. I have a function that when called, spits out an array of a products' ups prices, something like this. (I can have multiple products, not just 3): code:
code:
|
# ? Nov 29, 2012 05:19 |
|
Assuming your array is named $array:php:<? $result = array(); foreach ($array as $element) { foreach ($element as $key => $value) { $result[$key] += $value; } } print_r($result); ?> For my test array I used: php:<? $array = array( array( 'key1' => 5, 'key2' => 6, 'key3' => 7), array( 'key1' => 1, 'key2' => 2, 'key3' => 3));?> php:<? Array ( [key1] => 6 [key2] => 8 [key3] => 10 ) ?>
|
# ? Nov 29, 2012 05:39 |
|
The Gripper posted:
with all sincerity, THANK YOU! I really appreciate the fast response.
|
# ? Nov 29, 2012 05:55 |
|
I'm working on a kind of 'refresher' project that involves pointing a user to one of three different stories (effectively altering keywords to change the atmosphere) based on their responses to 5 questions. My original idea was to have the keywords I mentioned before stored in an array and called at the appropriate part of the story. This should be pretty simple stuff if I wasn't so rusty. I used a simple quiz I found on CSS-Tricks and, with a little help from the guys and gals at Stack Overflow, got it working pretty much as I wanted it to work, only with a few caveats: php:<? $answer1 = $_POST['question-1-answers']; $answer2 = $_POST['question-2-answers']; $answer3 = $_POST['question-3-answers']; $answer4 = $_POST['question-4-answers']; $answer5 = $_POST['question-5-answers']; $responseA = 0; $responseB = 0; $responseC = 0; //Calculates which response has been selected most (3 code blocks removed for ease of reading) if ($answer1 == "A") { $responseA++; } elseif ($answer1 == "B") {$responseB++; } elseif ($answer1 == "C") {$responseC++; } if ($answer2 == "A") { $responseA++; } elseif ($answer2 == "B") {$responseB++; } elseif ($answer2 == "C") {$responseC++; } //SHOULD load the appropriate link but has a bias towards A and B. if ($responseA) { echo '<a href="sin.php">Next Page</a>'; } elseif ($responseB) { echo '<a href="mys.php">Next Page</a>'; } elseif ($responseC) { echo '<a href="ils.php">Next Page</a>'; } ?> Is that even possible with just php? If so, any help would be massively appreciated.
|
# ? Dec 10, 2012 19:57 |
|
Your comment says "Calculates which response has been selected most", but the code you provided does not do that. It calculates the number of times that A, B, and C have been picked. It then goes to sin.php if A has been picked at all, mys.php if A has not been picked but B has, and ils.php if only C has been picked. What did you intend if ($responseA) to do? What is the "it" that you plan to put into an array?
|
# ? Dec 10, 2012 20:46 |
|
Musical Vomit posted:with a little help from the guys and gals at Stack Overflow, got it working pretty much as I wanted it to work I was the downvoter on that one, by the way. Not because it's a really bad question, but because the idiots doing new post reviews are upvote-happy and that's not a +2 question as asked. Are you trying to basically "score" the responses to pick the next page? Stick the scores in array, do a key-preserving reverse sort on it, and act on that. One heck of a lot easier than the if/elseif block at the bottom. You should also change your form element naming. You stick square brackets in the name, and PHP will automatically build an array inside $_POST. For example, instead of name="question-1-answers", use name="question_answers[1]", then do something like php:<?php $answer_counts = array( 'A' => 0, 'B' => 0, 'C' => 0 ); foreach($_POST['question_answers'] as $question_number => $answer) $answer_counts[$answer]++ arsort($answer_counts); $winning_answer = key($answer_counts); McGlockenshire fucked around with this message at 21:24 on Dec 10, 2012 |
# ? Dec 10, 2012 21:20 |
|
Amarkov posted:Your comment says "Calculates which response has been selected most", but the code you provided does not do that. It calculates the number of times that A, B, and C have been picked. It then goes to sin.php if A has been picked at all, mys.php if A has not been picked but B has, and ils.php if only C has been picked. That's simply poor commenting on my part, I'm afraid. I usually start commenting things when I'm troubleshooting and by that point I'm exhausted. Truthfully, I was thinking about re-writing the "quiz" script completely to incorporate the entire thing into an array ("it"). I'm sure it's possible, but the mechanics are far beyond my level of knowledge, especially from scratch. if ($responseA/B/C) was supposed to point to one of the other pages depending on the results. Maybe it'll be better understood if I try to explain the original idea: Quiz outputs to an array and the appropriate keywords place in the necessary part of the story (eg: print "“Very good.” The voice stated, sounding more " . $mystery[0]). The issue with that appears when I try to pick the correct variable for the story based entirely on the results. If you need any further clarification, I'll be happy to explain as best I can. EDIT: McGlockenshire posted:I was the downvoter on that one, by the way. Not because it's a really bad question, but because the idiots doing new post reviews are upvote-happy and that's not a +2 question as asked. Hah! I totally understand and it seems to be the same on a lot of SO's sites. I was actually confused as to even getting 1 upvote! Yes, that's exactly what I mean. I'll certainly try that out in a bit and see how it works, thank you for that. I'm still not entirely sure what to do about ties but right now that's not too big of an issue right now. I'm more concerned about getting it working. Musical Vomit fucked around with this message at 21:50 on Dec 10, 2012 |
# ? Dec 10, 2012 21:38 |
|
Musical Vomit posted:if ($responseA/B/C) was supposed to point to one of the other pages depending on the results. Yes, but under what conditions? For instance, when should the link point to mys.php?
|
# ? Dec 10, 2012 23:17 |
|
Amarkov posted:Yes, but under what conditions? Ah, I see what you were asking. My apologies. There are 5 questions with 3 answers each (A/B/C). Assuming the user selects mostly A, then the code will return sin.php, likewise for B (mys.php) and C (ils.php). Ties are still up in the air and that's a bridge I will cross when it arrives. Edit: Forgot to mention: that piece of code works flawlessly! Thanks guys. You have no idea how much I appreciate it. Musical Vomit fucked around with this message at 00:10 on Dec 12, 2012 |
# ? Dec 11, 2012 18:05 |
|
How do you guys like PhpStorm? It's on sale for $25 right now. http://www.jetbrains.com/specials/index.jsp Kind of thinking about it but using EditPlus and a VM seem to work fine.
|
# ? Dec 21, 2012 00:42 |
|
KNITS MY FEEDS posted:How do you guys like PhpStorm? It's on sale for $25 right now. This is a great deal and you should do it- PhpStorm is probably the best PHP IDE out there.
|
# ? Dec 21, 2012 00:50 |
Null Set posted:This is a great deal and you should do it- PhpStorm is probably the best PHP IDE out there. This is awesome, my PyCharm trial is about to expire.
|
|
# ? Dec 21, 2012 02:06 |
|
Is there any preferred method for executing a function that's stored in a variable name? Between variable functions and call_user_func() (or some other method), does one have any advantages or disadvantages? pseudorandom fucked around with this message at 20:59 on Jan 1, 2013 |
# ? Jan 1, 2013 20:53 |
|
While you can just $funcname(), it's "safer" and more extensible to use call_user_func, as it'll also take arrays (for calling static methods on classes and instance methods on objects), which the first form doesn't. Both of the two work for PHP 5.3 anonymous functions.
|
# ? Jan 2, 2013 06:57 |
|
In Php, with calculations, does it always round up? I need to be able to get an answer as 94.157 instead of 94.16. Any help or point in the right direction is appreciated.
|
# ? Jan 8, 2013 00:33 |
|
Use the round() function to set the precision of a number. http://php.net/manual/en/function.round.php
|
# ? Jan 8, 2013 01:06 |
|
I'm diving into the strange world of XML now, and the documents I have to work with suck and I can't figure out how to pull any info out of them. It's output from another program so changing it isn't doable, at least not right now. The project is to pull the XML that is spit out by an RC scoring program and have my own site parse it to display the results of an event going on so participants can check the site to see what's going on. To do this, I'm hijacking the XML file that normally gets sent to a third-party (LiveRC.com). Since it's not Flash or JS, I won't get the live updating they do, but whatever. It's just a for-the-hell-of-it project right now. My XML for the entry list looks like this: code:
For now I'm just trying to spit out the class names, and here's my terrible attempt at it: php:<? $source = @simplexml_load_file('xml/entryList.xml'); $xml = simplexml_load_string($source); foreach($xml->LiveRCData->ClassData->Class[0]->attributes(name) as $classname) { echo $classname; } ?> TremorX fucked around with this message at 05:26 on Jan 9, 2013 |
# ? Jan 9, 2013 04:48 |
|
Well, I think your only real problem is how you're loading the xml file.php:<? $source = @simplexml_load_file('xml/entryList.xml'); ?> var_dump($source) shows the contents to be correct: php:<? object(SimpleXMLElement)#1 (2) { ["ClassData"]=> object(SimpleXMLElement)#2 (1) { ["Class"]=> array(2) { [0]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(2) { ["name"]=> string(16) "2WD Short Course" ["classID"]=> string(1) "1" } } [1]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(2) { ["name"]=> string(11) "Nitro Buggy" ["classID"]=> string(1) "2" } } } } ["DriverData"]=> object(SimpleXMLElement)#3 (1) { ["Driver"]=> array(2) { [0]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(4) { ["name"]=> string(12) "Racer, Speed" ["classID"]=> string(1) "1" ["transponder"]=> string(7) "1234567" ["DriverID"]=> string(4) "1234" } } [1]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(4) { ["name"]=> string(10) "Racer, Rex" ["classID"]=> string(1) "1" ["transponder"]=> string(7) "8901234" ["DriverID"]=> string(4) "5678" } } } } } ?> edit; php:<? $source = simplexml_load_file('arse.xml'); foreach ($source->ClassData->Class as $class) { echo $class->attributes()->name."\n"; } ?> The Gripper fucked around with this message at 05:24 on Jan 9, 2013 |
# ? Jan 9, 2013 05:14 |
|
OK, I think I understand... you pull each Class record and then display the attribute in the echo instead of trying to pull out the attribute with the loop. Also, I don't need to bother with the main parent field. I think this will work... Thanks!!!
TremorX fucked around with this message at 05:38 on Jan 9, 2013 |
# ? Jan 9, 2013 05:36 |
|
Yeah, since there's multiple Classes in that XML you'll loop over them to get each individually, and then get the attributes you want from that. In your original you were just looping through the first Class's (Class[0]) attributes (improperly), so even if it worked you wouldn't be getting the full data anyway.
|
# ? Jan 9, 2013 05:42 |
|
That worked incredibly well! One more question, though. In that same file, there's essentially what would be a one-to-many relationship in SQL -- the Class has a name and an classID, but the Driver only includes the classID. Let's say I want to separate out the drivers in each class and list them. If this were MySQL I'd just build a query and go about living the rest of my life, but I have absolutely no idea how to do that with XML (I'm a total Novice at PHP, if you haven't figured that out yet.) Any ideas of how to do it/where to look? And never mind that never mind, turns out the two variables were mismatched. I settype both to INT and now it all works! php:<? foreach ($xml->ClassData->Class as $class) { $className = @$class->attributes()->name; $classID = @$class->attributes()->classID; settype($classID, 'int'); if(!($className == "(null)")){ echo "<h2>".$className."</h2>"; } foreach ($xml->DriverData->Driver as $driver) { $driverName = $driver->attributes()->name; $driverClass = $driver->attributes()->classID; settype($driverClass, 'int'); if ($classID == $driverClass) { echo $driverName."<br />"; } } } ?> TremorX fucked around with this message at 04:18 on Jan 10, 2013 |
# ? Jan 10, 2013 03:09 |
|
You guys using Laravel, when interacting with the database, what do you prefer (raw query, fluent, eloquent)? I just can't get into Eloquent but so many people say to use it. And fluent is just a dummy proof way to write raw queries. Therefore I typically prefer to use raw queries. Is there anything wrong with this? Should I be learning to use Eloquent?
|
# ? Jan 10, 2013 16:22 |
|
IT Guy posted:You guys using Laravel, when interacting with the database, what do you prefer (raw query, fluent, eloquent)? I haven't encountered any huge differences but I prefer to use Eloquent just so I'm not rewriting table names all the time. I'm still learning but Eloquent seems a lot cleaner to write out once you define the model.
|
# ? Jan 10, 2013 17:48 |
|
IT Guy posted:You guys using Laravel, when interacting with the database, what do you prefer (raw query, fluent, eloquent)? Eloquent is the bee's knees. It took me a little bit of work and a lot of reading to fully understand it, but it's worth it. If you ever get completely stuck you can browse the actual Laravel code on their web site as well.
|
# ? Jan 11, 2013 05:59 |
|
Ok, I've decided to just suck it up and use Eloquent. I guess I'm just old fashion in that I like full control of my queries. I've never used an ORM and Laravel is my first framework. After reading so many SQL books and learning to always specify table names and harden your queries, it's weird going to an ORM.
|
# ? Jan 11, 2013 15:04 |
|
Ugh, Eloquent. I don't have access to my server at the moment so I'll ask here. Do I really need an auto-incrementing surrogate "id" column on all my tables (especially my lookup table) for Eloquent to work? (as seen here) Everything about Eloquent seems to just throw all SQL best practices out the window. IT Guy fucked around with this message at 04:52 on Jan 13, 2013 |
# ? Jan 13, 2013 04:50 |
|
IT Guy posted:Ugh, Eloquent. I don't know anything about that specific framework but it wouldn't surprise me. I was dismayed to find out that Django has exactly that requirement when I was investigating it.
|
# ? Jan 14, 2013 13:49 |
|
Hammerite posted:I don't know anything about that specific framework but it wouldn't surprise me. I was dismayed to find out that Django has exactly that requirement when I was investigating it. I just tried it out on my server, you do need the auto-incrementing "id" column in addition you also need the created_at and updated_at fields, even if you don't care to track those timestamps. Even setting: "public static $timestamps = false;" still requires the timestamps. I don't understand the hype about ORMs.
|
# ? Jan 14, 2013 15:45 |
|
|
# ? Jun 1, 2024 08:52 |
|
IT Guy posted:I don't understand the hype about ORMs. SQL scares people. This is also why NoSQL (Mongo, Redis, etc.) had a popularity surge recently. More seriously, the idea is that it's meant to make your code more portable (you could theoretically deploy on any DB engine and the ORM takes care of it), and allow you to build in a more OOP way. The problem is that for a non-trivial system, an ORM just gets in the way because it can't easily and automatically encapsulate the complex relationships between your objects, or even data in a single object. I don't like them, other than Python's SQLAlchemy, and even then, I use it in a very manual way.
|
# ? Jan 14, 2013 23:52 |