Jump to content


  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

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

ChenXiu's Achievements

Advanced Member

Advanced Member (4/5)




Community Answers

  1. I am not the owner of the "links" you want me to onClick. [Admins: if you want to delete this entire thread, that might be a good idea -- it is obvious I did a terrible job of describing the scenario.] There are several big-company 3rd party "Top 10 places to Sell Widgets" out there that I have no control over. Like this big company fictitious website: "Top10widgets.com: GET BEST PRICES FOR YOUR WIDGETS" Visitor has widget they want to sell. They go to Top10widgets.com and input SKU number "ABCXYZ" onto their page, and sees a list like this: ChenXiuThisIsMe.com: $6.00 <a href="https://myCompany.com/referal.php?referer=top10widgets&SKU=ABCXYZ">SELL HERE</a> Somecompany1.com $5.00 <a href="https://myCompany.com/referal.php?referer=top10widgets&SKU=ABCXYZ">SELL HERE</a> Somecompany2.com $4.00 <a href="https://myCompany.com/referal.php?referer=top10widgets&SKU=ABCXYZ">SELL HERE</a> Somecompany3.com $3.00 <a href="https://myCompany.com/referal.php?referer=top10widgets&SKU=ABCXYZ">SELL HERE</a> Somecompany4.com $3.00 <a href="https://myCompany.com/referal.php?referer=top10widgets&SKU=ABCXYZ">SELL HERE</a> Visitor sees my company at the top of that list, offering the best price, and chooses my company by clicking that "SELL HERE" link. I have no control over the Top10widgets.com whether they use onclick, target_blank, etc. What they have is what they have. It's a referral link that sends visitor to my website. If visitor is already on my website with $_POST values of widgets they've already priced, then midstream visitor decides to go to Top10widgets.Com and clicks their "SELL HERE" link to bring them back to my website, all existing $_POST data on my website gets lost because the "SELL HERE" link on Top10widgets.com is a $_GET request.
  2. I love the idea of Ajax (thank you Barand!). But I should have explained better. The visitor manually prices their widgets on my website to see my offering prices, like this: 1.) Visitor has a box of 5 widgets sitting on their desk. 2.) Visitor manually types in the SKU numbers from those 5 widgets and clicks "Submit" to see my Offering Prices. 3.) Visitor may enter all 5 SKU numbers at once, click "Submit" and see all 5 prices all at once, or, they can enter and submit them one-at-a-time, until all 5 widgets appear with prices. 4.) NORMALLY, the Visitor would then enter their name and address and click "Complete Order" and then a Packing Slip is generated. However, before the visitor "completes their order," they might choose to price one of those widgets on one of those 3rd-Party "Best Price" comparison-style websites that are popularly used for pricing widgets. Those 3rd Party websites have all of us companies listed, with our respective offering prices, and a "Sell Here" button next to each of our company's prices: <a href="https://myWebsite/link.php?Referer=RefererCompany&SKU=XYZ>Sell Here</a> When the visitor clicks that "Sell Here" button on that 3rd party website, that causes the Pricing Page described above to reload with the $_GET request, thus causing all the $_POST data from the previously priced 5 widgets to vanish. (Unless I use Sessions) So although I hope I somehow could use Ajax, I don't see how it would fit in. I hope there is a way to use Ajax -- I'm all ears on any suggestions on this. (And, of course, any alternatives if Ajax is not possible.) p.s. @Gizmola.... you said, "This sounds like a "you" problem." haha -- yes, you caught me there -- okay, so maybe not 1000 lines of code, maybe just 15 lines of code.... but I've always aspired to always use really short "one-liner" code.... so to me, 15 lines of $_SESSION code really does feel like 1000 lines 😀 Also, my website is intentionally designed so visitors never have "register" or "log in." Although having required registration/login would programatically solve lots of issues, my customers demand to not have to "log in" (they consider "not having to register" to be a feature). p.s.3 Oh my goodness... I think this is my longest ever post :-) But I'm thisssss closssseeee [making pinching finger gesture] to being all done 😀😀😀
  3. ALMOST DONE WITH MY WEBSITE! LAST HURDLE AS FOLLOWS (then I won't bother you guys no more hehe) Visitors add SKU numbers to my website in GROUPS AT A TIME to see prices like this SKU# XYZ = $10.00 Then they add another couple SKUs, like this: SKU# ABC, SKU# PQR........ and then they see this: SKU# XYZ = $10.00 SKU# ABC = $20.00 SKU# PQR = $5.00 .... and when they're done they put in their name and address and voila! They have a packing slip. All the data they enter is contained in a PHP $_POST variable using <input type="hidden" name="sku_numbers" value="implode($posted_sku_number__array)"> and then reposted as they keep adding more stuff. Everything's fine unless midstream if they decide to click a referral link to add a referred sku number (https://myWebsite/link.php?Referer=RefererCompany&SKU=XYZ) Obviously, if they decide to click the link, it's a $_GET request, and all my $_POST data vanishes. 😡 So I implemented Sessions, and now my website saves $_POST inside of $_SESSION, and then if a GET request is made, $_POST is repopulated from $_SESSION. Like this: if ($_SERVER['REQUEST_METHOD'] === 'POST') { $_SESSION["post"] = $_POST; } if(isset($_GET)) { if(isset($_SESSION["post"])) { $_POST = $_SESSION["post"]; } } My website now works, but I don't like it. I don't like sessions, I don't like 1000 lines of code to make sessions work, and unless I have session_unset() in all the right places, and 1% of the time there's the odd unexpected result.....like if a visitor completes an order with 50 SKUs, then starts over with just 1 sku, the pricing page will still show those last 50 skus because I forgot to unset one of the $_SESSION variables... QUESTION: All this get/post/session nonsense could be AVOIDED if that referral link thingy could be turned into a POST request instead of a GET request so I don't lose all my $_POST data. CAN SUCH A THING BE DONE: TURN A REFERRAL GET LINK INTO A POST AS DESCRIBED ABOVE? Thank you in advance.
  4. Thank you! That was my next step -- a string function! Especially since string-style functions are much faster than preg_match. It's funny, I had been thinking "just this one time I'll use preg_match in my coding to save time," and now it's days later, 3 days wasted (I thought preg_match "capture this group as long as it doesn't contain" would be easy, but all the answers I have found are as convoluted as a furniture assembly manual haha.) Thank you again!!
  5. The input $string will only have one parenthesis with the word "required" in it (it will never show up more than once). The very best I could come up with is the following disgustingly obtuse code: \(((?![\(]).)*required\) I will not use this code because: 1.) it makes 2 capture groups, which is stupid. 2.) it is disgustingly obtuse. There must be an elegant one liner a pro, such as yourself, would use 😀
  6. Desired: Use preg_match to capture only the parentheses containing the word "required." Example: $string = 'Large toolbox (metal) for sale (hammer is required) serious inquiries only.'; Desired: (hammer is required) $string = 'Meeting scheduled for Tuesday (Formal attire required) otherwise call (or email) us.'; Desired: (Formal attire required) I would be happy to share the 3-days worth of experiments I tried, but posting said experiments would not be pretty, and, most importantly, would show my IQ. Thank you in advance!
  7. Oooops. I totally goofed up. Please ignore the above question. Here is what I did: I ran the "create table..." command, but kept getting frustrated that the "price" column didn't change. "select price from....." why the heck won't it change!?!?!? Duh! OF COURSE the price column doesn't change -- it's the "MAX(price)" column that gets the updated price. This is such a stupid mistake I made. 😀
  8. Greetings! This one makes my head spin 😀 Scenario: 2 existing mySQL tables of merchandise lists with Primary Key (SKU_number) Note: Both tables often have identical SKU numbers. Desired: New table combining the 2 tables, Primary Key (SKU_number) If the 2 existing mySQL tables contain the same SKU_number, the new Table should have highest price. Example: existing tableONE; +-------------+-------------+-------+ | SKU_number | description | price | +-------------+-------------+-------+ | 222222 | big hammer | 13.00 | | 444444 | good knife | 10.00 | | 666666 | small screw | 8.00 | | 888888 | bolt | 2.00 | +-------------+-------------+-------+ existing tableTWO; +-------------+--------------+-------+ | SKU_number | description | price | +-------------+--------------+-------+ | 111111 | saw | 7.00 | | 222222 | large hammer | 20.00 | | 444444 | good knife | 10.00 | | 666666 | tiny screw | 5.00 | +-------------+--------------+-------+ Brand new master table of both existing tables, and will have: • MAX price, when same SKU_number is in both tables • Product Description from tableONE, when same SKU_number is in both tables +-------------+--------------+-------+ | SKU_number | description | price | +-------------+--------------+-------+ | 111111 | saw | 7.00 | | 222222 | big hammer | 20.00 | | 444444 | good knife | 10.00 | | 666666 | small screw | 8.00 | | 888888 | bolt | 2.00 | +-------------+--------------+-------+ Here is the code I thought had been working, but just now discovered it didn't work when I swapped the table order 😀 create table MaxMaster as SELECT * , MAX(price) FROM ( SELECT * FROM tableTWO UNION ALL SELECT * FROM tableONE ) both_tables GROUP BY SKU_number; Thank you!
  9. Oooooh! That is fantastic! Like I've said lots before, I wish I had learned PHP from the ground up. This sounds like something every brand new PHP person already knows. So, yes, a "do loop" is exactly what I want. Tangentially, when I was "borrowing code" from an example I read somewhere for something else, they had a "try/catch" thing going on. I immediately got rid of the "try" and "catch" thinking "I don't need those stupid things whatever they are..." So, after I get comfortable using "do loops" I should brush up on what try/catch means and does 😃 As well as what 'break' 'continue' and 'next' actually mean (in my code above, using "break" was just a lucky guess 😊 ) p.s. I should have mentioned before... your use of time() in the code is fantastic -- that never would have occured to me. I thought a $counter + sleep() was the only way to do this sort of thing. Right now I can already think of a dozen places where I can use time() in a loop.
  10. Thank you! I've never used a "do" loop before; this will be my first one. Tomorrow morning I'm setting aside time to learn about them, pros and cons, and when to use. It looks elegant!
  11. No, you misunderstood. The 3rd party data provider can take up to one minute depending on how many customers are simultaneously using their service. The 3rd party provider produces results in about 1/4 second if 10 people are using their service. If 200 people are using their service, you're in a queue. When they provide the data is when they provide the data. Is my mySQL code okay?
  12. Data is supposed to be instantly inserted into mySQL table from a 3rd party. However, sometimes it takes up to a minute or so.... Is this "keep checking for up to a minute" loop okay? If not, how can I make it better? $count = 0; $query = $db->query("select data from mytable where sku = 'XYZ123' limit 1")->fetch_assoc(); // if no instant result, keep trying for up to one minute: while (!$query) { $query = $db->query("select data from mytable where sku = 'XYZ123' limit 1")->fetch_assoc(); sleep(1); // wait for one second before trying again $count++; if($count > 60) { break; } // Give up after one minute. } if (!$query) { echo 'Forget it, no data will be provided!'; // Give up. } else { echo 'Success! Data is ' . $query["data"]; // Success! } Thank you.
  13. That sounds like a great idea, thank you! I'll search for one now.
  14. p.s. in my real scripts, I have: $result = $db->query($query); while ($row = $result->fetch_assoc()) { ... } (otherwise none of my mySQL queries would work) But when I type my question here, I goofed it up. I'm noticing the following: I have at least 20 new coding ideas every single day. Whenever I try them out, they *always* generate some sort of an error. ... and then I have to go fix the error. Each time. Looking back this entire year, I think every single block of code I've written has generated some sort of an error which I have to go fix. ... hopefully this gets better 😃 I feel like a first grader in english class.... "The dog jumped over the fense." - oops.... "fence" "The three bares liked porridge" - oops... "bears" while($row = $result = fetch_assoc()....
  15. Thank you! Yes you are correct. I botched that one. And this is super basic stuff I should already know. Sometimes I wish I was in an actual (physical, not online) PHP classroom, and was made to learn PHP from the ground up, starting all the way from the beginning. There are so many rock-bottom absolute-basic things I have no clue about. One day, hopefully 😃
  • 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.