Jump to content

StevenOliver

Members
  • Content count

    45
  • Joined

  • Last visited

  • Days Won

    1

StevenOliver last won the day on November 25

StevenOliver had the most liked content!

Community Reputation

5 Neutral

About StevenOliver

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. StevenOliver

    cURL in background

    Thank you!! That's perfect. That's the only thing I neglected to try -- modifying the code to process XML on the server. (Why why WHY don't I think of these things?! 😀)
  2. StevenOliver

    cURL in background

    Thank you -- I think that will work perfect.... but made a mistake: the 3rd party data I am accessing is in XML format: <merchandise> <apiversion>4.0</apiversion> <items> <item> <name>Hammer</name> <price>7.50</price> <currency>USD</currency> </item> </items> </merchandise> I'm not sure how to modify the jQuery in your code to parse XML (the "$().ready(function()" portion). Simply changing "JSON" to "XML" or, var txt = resp["<price>"] doesn't work. I found some "solutions" on Google, but I would rather use concise style of scripting. How would I access, for example, the "price" in the XML?
  3. StevenOliver

    cURL in background

    I envision running code in the background without slowing my own PHP page render. This code accesses optional "Additional Information" via a 3rd party server API ("www.example.com/Additional_Information.php?SKU=1234567"). Unfortunately, it takes a full 10 seconds to retrieve the data from the 3rd party server, and, not all visitors will need this "Additional Information." My own server is fast -- it retrieves mySQL data from my server and renders the result to the Visitor in less than 4 milliseconds. Because it takes an average Visitor about 10 seconds to actually READ my entire page (description, photos, etc.), this would be a perfect time to run a script in the background so that if the Visitor chooses to click the "Additional Information" link, the data will already be available (because the background script would run in the background and post its results to my own mySQL server while the Visitor was busy reading). I've been studying asynchronous cURL calls, opening sockets, forking cURL, and even using cURL to call another cURL script on my server. These seem to slow down my PHP page render. Because not all visitors will want this "Additional Information," I don't want to slow my webpage down for everyone. Is there a way to have code 'truly run in the background' and post its result to my super-fast mySQL server, so if a Visitor does click on the "Additional Information" link, they'd get instant results from my own server?
  4. StevenOliver

    Display ALL records GROUP by Year/Month/Day with SUM

    Barand, Wow! Thank you -- that is fantastic code! I'm going line by line familiarizing myself with proper PDO code. For example, new DateInterval('P1Y') sets it to a period of 1 year, setTime(0,0, 0) sets the time ("timer") to zero. I'm now working on trying to understand how and why this line of code works: "$summary->execute([$start_date])" What worries me is that I never would have thought to do that (I wouldn't have made the leap to knowing that the StartDate input parameter could go in there). I guess that's why they call programming languages "languages" ... because analogous to learning a language, one might ponder, "How would I have known to call an apple an 'apple,' or, an orange an 'orange.'" You just do it! And do it over and over again until it becomes natural and second-nature. Thank you again!!
  5. StevenOliver

    Display ALL records GROUP by Year/Month/Day with SUM

    Using the aformentioned code, these statements work but I don't know how to properly nest them whereby the nested Prepared Query uses data retrieved by first Prepared Query: // Statement One $stmt = $db->prepare(" SELECT YEAR(timestamp_column) as yr , MONTH(timestamp_column) as mno , MONTHNAME(timestamp_column) as mth , DAY(timestamp_column) as da , SUM(salesPrice) as total FROM mysales GROUP BY yr, mno ORDER BY timestamp_column desc; "); // Statement Two $stmt2 = $db->prepare(" SELECT DAYNAME(timestamp_column) as dana , usedPrice FROM mysales WHERE MONTH(timestamp_column) = 11 // hard-coded month AND YEAR(timestamp_column) = 2018 // hard-coded year ORDER BY timestamp_column desc; "); // This works for first statement: $stmt->execute(); $result = $stmt->get_result(); while($row = $result->fetch_assoc()) { echo $row["mth"].'....'.$row["yr"].'...'.$row["total"].'<BR>'; } // This works for second statement: $result2 = $stmt2->get_result(); while($row2 = $result2->fetch_assoc()) { $stmt2->execute(); echo $row2["dana"].'...'.$row2["salesPrice"].'<BR>'; } Nesting them like this "somewhat" works.... but 1.) Seems inefficient, and just plain wrong to execute "$stmt2->execute();" and "$result2 = $stmt2->get_result();" inside a 50000-record "while loop." 2.) Only works for a "hard-coded" month and year (don't know how to pull data retrieved from first Statement.... e.g. hard-coded year "2018" works, but "$row['yr']" doesn't) I don't know what to do...
  6. StevenOliver

    Display ALL records GROUP by Year/Month/Day with SUM

    Gizmola, thank you for that clarification -- both codes indeed work fine on my server. I like Barand's "monthname" -- I'm always pleasantly surprised how mySQL is so "natural speaking friendly. And, I like your "order by" clause -- so I can have the recent activity first. Although the "drill down" php code will be a challenge, I'm confident I can that done (or at least make a dent in it) now that I have a better grasp of the logic. As a side note..., I'm always mildly annoyed at websites that only display "10" or "20" or "50" of something, and then requiring clicking a "display more" button on the bottom of the page. Maybe this was necessary 20 years ago when we all had 19.2k telephone line modems. But nowadays (with faster browsers and faster connections and all), displaying 5000 records is just as fast as displaying 20. I'm tempted to make my PHP page show a basic summary at the top (using the "group by" code described in this thread), followed by a display of all 20,000+ records. (Maybe not, just thinking out loud :-) (PHP is so fun... I've been waiting all day to get back to my computer to dig in to this!)
  7. StevenOliver

    Display ALL records GROUP by Year/Month/Day with SUM

    Barand, thank you! That is exactly what I was looking for -- code that makes sense, and code that doesn't give PHP unnecessary work. (As a novice, I often revisit code I've written and find I've given PHP unnecessary work that it didn't need to do :-)
  8. I am needing help with the mySQL "logic" portion of this please. My "viewLog.php" page accesses a huge table with "TIMESTAMP" and "sales Price." | timestamp_column |salesPrice | +---------------------+-----------+ | 2017-01-03 19:57:07 | 5.00 | | 2018-08-14 15:00:16 | 50.00 | | 2017-10-09 06:15:12 | 10.00 | | 2018-09-22 06:41:37 | 30.00 | | 2018-09-04 06:41:37 | 20.00 | | 2018-09-04 11:42:30 | 10.00 | Displaying all records on one page would be a mile long :-) How would I display everything grouped on one page? Like this (using data from the example table above): 2018 September's total: $60.00 August's total: $50.00 2017 October's total: $10.00 January's total: $5.00 Those totals would be hyperlinked so they would expand into "daily details" when clicked: 2018 September's total: $60.00 ↓ September 04, 2018 at 06:41:37 $20.00 September 09, 2018 at 11:42:30 $10.00 September 22, 2018 at 06:41:37 $30.00 Other than PHP requesting all dates from mySQL and grouping them into endless arrays, foreach loops, etc., is there an efficient (and elegant) one-liner that already does this sort of thing? (I know how to do basic mySQL "group by" requests, but can't get my head around the logic to do the above). Thank you.
  9. StevenOliver

    mySQL day/time Best Practices

    Thank you, I shall do that!!
  10. StevenOliver

    mySQL day/time Best Practices

    Thank you for your reply. I just now looked up "DATETIME vs TIMESTAMP" and found that mySQL's native "DATETIME" is faster and lighter, but TIMESTAMP is better when dealing with time zones. I wonder if TIMESTAMP would indeed be better because of the finicky server (I think my webhost uses several servers located in different time-zones which makes me have to readjust DateInterval('PT7H') every few days)?
  11. StevenOliver

    mySQL day/time Best Practices

    Thank you for replying -- I'll go ahead and change my column definition. The way I currently have it is really devoid of logic 😁 I like your way better than mine!
  12. StevenOliver

    mySQL day/time Best Practices

    I want to be able to record the date and time of page visits. And then later, view them grouped by day or month. What is the "best practices" way to do this? (Googling this, I find two philosophies:1.) letting mySQL create the time stamp, and 2.) letting PHP create the time stamp, and inserting this value into mySQL.) Currently, page displays "November 22, 2018 at 6:19am" to visitor, and then inserts this value into mySQL table using this code: $date = new DateTime(); $currentTime = $date->sub(new DateInterval('PT7H'))->format('F j Y \a\t g:ia'); echo $currentTime; // also, insert $currentTime into mySQL table.... But server is finicky!I have to adjust DateInterval('PT7H') every few days (off by one or more hours), and, this code doesn't lend itself to "selecting by day/month/year" in mySQL. Thank you.
  13. StevenOliver

    Declaring Variable Hell

    OMG that is fantastic! Simple, and clean! I wish I could completely relearn PHP as it's written nowadays. The way I "learned PHP" back in 1999 was you leave "Register Globals" set to "ON" and "display errors" set to "OFF" 😁
  14. StevenOliver

    Declaring Variable Hell

    Thank you for answering so quickly! I can already see where assigning default values is better than my blanket list where everything = "". I will do that now. When writing code, if a Notice is thrown "undeclared index line 1500," is it better to declare the default value on line 1499? Or at the very top of the page (like in my aforementioned example)? Thank you.
  15. StevenOliver

    Declaring Variable Hell

    Am rewriting someone's thousand-line late-90's PHP script. Error-Reporting shows a gazillion 'Notices' -- almost all of them "Undeclared Index" and "Undeclared Variable." To temporarily correct these Notices, I've simply declared all of them at the top of my PHP page like this: $_POST["merchandise_name"] = isset($_POST["merchandise_name"]) ? $_POST["merchandise_name"] : ''; $_POST["customerNumber"] = isset($_POST["customerNumber"]) ? $_POST["customerNumber"] : ''; $loop_counter = isset($_POST["loop_counter"]) ? $_POST["loop_counter"] : NULL; $anotherVariable = isset($_POST["anotherVariable"]) ? $_POST["anotherVariable"] : NULL; // etc., etc., there's about 50 more below This looks amateurish and improper. Is there a better way? Thank you.
×

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.