Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
stoops
Jun 11, 2001
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.

Adbot
ADBOT LOVES YOU

The Gripper
Sep 14, 2004
i am winner
You could just do ceil(x/10) * 10 where x is your total.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
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

tridens
Feb 3, 2007

Hooya hey
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!

The Gripper
Sep 14, 2004
i am winner
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.

tridens
Feb 3, 2007

Hooya hey

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.

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.

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.....

The Gripper
Sep 14, 2004
i am winner

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.
I'm not sure it's using the older OpenID protocol, it's just accessing the non-standard attributes which the Paypal profile endpoint doesn't provide (since they don't have a direct mapping to an OpenID schema). It's listed on the URL I provided under Paypal Specific Attributes. 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.

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.

tridens
Feb 3, 2007

Hooya hey

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.

The Gripper
Sep 14, 2004
i am winner
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.

tridens
Feb 3, 2007

Hooya hey

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

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
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?

stoops
Jun 11, 2001
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:
Array ( 

[0] => Array
( 
[3 Day Select] => 24.00 
[2nd Day Air] => 31.58 
[Next Day Air Saver] => 48.05 
[Next Day Air] => 57.17 
[Next Day Air Early AM] => 92.51
) 

[1] => Array
( 
[3 Day Select] => 24.00 
[2nd Day Air] => 31.58 
[Next Day Air Saver] => 48.05 
[Next Day Air] => 57.17 
[Next Day Air Early AM] => 92.51
) 

[2] => Array
( 
[3 Day Select] => 18.35 
[2nd Day Air] => 23.09 
[Next Day Air Saver] => 37.96 
[Next Day Air] => 45.26 
[Next Day Air Early AM] => 80.60
) 

)

After this runs, I would like to sum all the prices and just spit out one array like this

code:
Array
( 
[3 Day Select] => sum of all 3 day selects
[2nd Day Air] => sum of all 2nd day Airs
[Next Day Air Saver] =>sum of all Next Day Air Savers 
[Next Day Air] => sum of all  Next Day Airs
[Next Day Air Early AM] => sum of all  Next Day Air Earlys
)

Can this be done? Any help is appreciated and or point to the right direction. I know i'm needing a loop but i'm not sure how to achieve that.

The Gripper
Sep 14, 2004
i am winner
Assuming your array is named $array:
php:
<?
$result = array();

foreach ($array as $element) {
  foreach ($element as $key => $value) {
    $result[$key] += $value;
  }
}
print_r($result);
?>
Loops through each element of your original array (each product), then loops through each price and updates a $result array with the same keys as your original array (3 Day Select, etc.) with a cumulative total.

For my test array I used:
php:
<?
$array = array( array( 'key1' => 5, 'key2' => 6, 'key3' => 7), array( 'key1' => 1, 'key2' => 2, 'key3' => 3));?>
And the output is:
php:
<?
Array
(
    [key1] => 6
    [key2] => 8
    [key3] => 10
)
?>

stoops
Jun 11, 2001

The Gripper posted:


Loops through each element of your original array (each product), then loops through each price and updates a $result array with the same keys as your original array (3 Day Select, etc.) with a cumulative total.


with all sincerity, THANK YOU! I really appreciate the fast response.

Musical Vomit
Feb 14, 2009
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>'; }
?>
So, after spending a few hours of fighting with the code to figure out why it's so biased towards response A and B (if you click C, it will rarely work and I assume it's down to how php parses code and my awful edit-coding), I decided it would likely be easier all around if I were to go with my original idea and put it into an array. The issue, of course, is how to output the results from the quiz into an array and then display the appropriate responses from an array of all possible keywords on one page.

Is that even possible with just php? If so, any help would be massively appreciated.

Amarkov
Jun 21, 2010
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?

McGlockenshire
Dec 16, 2005

GOLLOCKS!

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. :colbert:

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' => );
foreach($_POST['question_answers'] as $question_number => $answer)
    $answer_counts[$answer]++
arsort($answer_counts);
$winning_answer key($answer_counts);

This doesn't handle ties.

McGlockenshire fucked around with this message at 21:24 on Dec 10, 2012

Musical Vomit
Feb 14, 2009

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.

What did you intend if ($responseA) to do? What is the "it" that you plan to put into an array?

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. :colbert:

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' => );
foreach($_POST['question_answers'] as $question_number => $answer)
    $answer_counts[$answer]++
arsort($answer_counts);
$winning_answer key($answer_counts);

This doesn't handle ties.

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

Amarkov
Jun 21, 2010

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?

Musical Vomit
Feb 14, 2009

Amarkov posted:

Yes, but under what conditions?

For instance, when should the link point to mys.php?

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

Acer Pilot
Feb 17, 2007
put the 'the' in therapist

:dukedog:

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.

Null Set
Nov 5, 2007

the dog represents disdain

KNITS MY FEEDS posted:

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.

This is a great deal and you should do it- PhpStorm is probably the best PHP IDE out there.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

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.

pseudorandom
Jun 16, 2010



Yam Slacker
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

McGlockenshire
Dec 16, 2005

GOLLOCKS!
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.

stoops
Jun 11, 2001
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.

Mister Chief
Jun 6, 2011

Use the round() function to set the precision of a number.

http://php.net/manual/en/function.round.php

TremorX
Jan 19, 2001

All Hail Big Hairy Mike

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:
<LiveRCData>
     <ClassData>
           <Class name="2WD Short Course" classID="1" />
           <Class name="Nitro Buggy" classID="2" />
     </ClassData>
     <DriverData>
           <Driver name="Racer, Speed" classID="1" transponder="1234567" DriverID="1234" />
           <Driver name="Racer, Rex" classID="1" transponder="8901234" DriverID="5678" />
     </DriverData>
</LiveRCData>
Yes, none of the actual data is stored in a field, it's getting stuffed into an attribute. All of the other XML files are set up this way, too, so if I can solve this one I'm good.

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;
        }
?>
Nothing happens. I've never messed with simpleXML before today so I have no idea if this is even the right way to go about it. Any suggestions?

TremorX fucked around with this message at 05:26 on Jan 9, 2013

The Gripper
Sep 14, 2004
i am winner
Well, I think your only real problem is how you're loading the xml file.

php:
<?
$source = @simplexml_load_file('xml/entryList.xml');
?>
Will load the XML from file and process it, so you don't need to then call simplexml_load_string() on the result (simplexml_load_string() expects a bare string with XML contents).

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"
        }
      }
    }
  }
}
?>
From there you should be able to pull all the data you need out of $source with no issue.

edit;
php:
<?
$source = simplexml_load_file('arse.xml');

foreach ($source->ClassData->Class as $class) {
  echo $class->attributes()->name."\n";
}
?>
Will do what your original code wanted to do.

The Gripper fucked around with this message at 05:24 on Jan 9, 2013

TremorX
Jan 19, 2001

All Hail Big Hairy Mike

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

The Gripper
Sep 14, 2004
i am winner
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.

TremorX
Jan 19, 2001

All Hail Big Hairy Mike

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?

edit - poo poo, and as I finish typing that I think I figured it out using nested foreach loops ... but still, I'm open to suggestions. Nevermind, that's not working, either.

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

IT Guy
Jan 12, 2010

You people drink like you don't want to live!
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?

Fluue
Jan 2, 2008

IT Guy posted:

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?

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.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

IT Guy posted:

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?

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.

IT Guy
Jan 12, 2010

You people drink like you don't want to live!
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.

IT Guy
Jan 12, 2010

You people drink like you don't want to live!
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

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

IT Guy posted:

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.

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.

IT Guy
Jan 12, 2010

You people drink like you don't want to live!

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.

Adbot
ADBOT LOVES YOU

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply