Jump to content

phppup

Members
  • Posts

    912
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by phppup

  1. I'm assuming some of this is a bit of shorthand for IF clauses. It offers a new logic approach, so I'll give it a shot. Thanks.
  2. Envision this: IVs can be used to replace pills, but are more expensive than pills. Pills can be used to replace syrup, but are more expensive than syrup. Ideally, each room has a supply of 2 IVs, 4 pills, and 8 syrup. However, if an item falls below a threshold, it may indicate a supply shortage and therefore triggers a bulk-up of the higher teir item for an overstocking response (with a ceiling for the next cycle). Due to budget, only one overstock event of 10 units per room is allowed per cycle. Given these parameters, room 1 with 2 IVs and 4 pills would order no IVs or pills. However, once the syrup deficit is realized, the pill order needs to shift to 10 for overstock. No syrup is ordered due to budget, but a notification is sent to the procurement team. Hence, pills is reliant on "looking ahead" at syrup. Room 0 has one of 2 IVs. With that assessment, an order of 1 would be expected. But bc pills is below 4, an overstock is triggered for 10 IVs for room 0. Nothing else will be ordered for room 0 in this cycle. This is why there is a need to "see forward" in the array.
  3. I'm trying to "see ahead" in my associative array This hypothetical is the simplest way to describe what I'm trying to accomplish. I have an array that looks like this $arr = [ 0 => ["meds" => [ "IV" => 1, "pill" => 2, "syrup" = 3] ], 1 => ["meds" => [ "IV" => 2, "pill" => 4, "syrup" = 6] ], 2 => ["meds" => [ "IV" => 5, "pill" => 5, "syrup" = 5] ] ]; We have 3 rooms for patients that each contain the designated medication types. Using foreach() I can successfully run through the array. Example: if IV quantity is less than 3, create a message to order the amount that will bring inventory up to 3. Obviously this can be done uniformly. My problem: I want to "reach ahead" to affect a current element. Ex: while processing the order for IVs, if pills are less than 10 then do something (double the order, print in red) to IVs. Likewise, if pills are needed, do something, but do something more based on syrup. I've fumbled the idea of creating a new array and flipping the contents around, but nothing seems to be resolving my issue.
  4. @requinix i stubbornly gave the DOM some research. I got some strange responses so first, but then discovered how (hate to admit it) easy and effective it is. Some insight into is workings might be helpful now. I initially engaged DOM with some "broken" HTML that had already been a little mangled by stripos and offset cuts. When I re-oriented it by <p> it "repaired" my chopped-up <h2> lines. Is this a built-in benefit? How? Eventually I ran the DOM code properly and can see it's effectiveness. I guess at this point it's just a matter of signing the correct loops to gather and distribute the data as I desire. Right? So, are the ole days of stripos and string contents now antiquated? Thanks for the help.
  5. Late night and lacking sleep is no time to mingle with stripos. I was playing with some sloppy code and I could use a hand to get it of my mind. Here are the essentials of what I have //a string of HTML to throw into a variable $page ="<h2> item 1 </h2> <p> day </p> <p> time </p> <h2> item 2 </h2> <p> day </p> <p> time </p> <h2> item 3 </h2> <p> day </p> <p> time </p>"; $start = stripos($page, 'h2'); $end = stripos($page, '/h2'); $len = $end - $srart$html_section = $find = substr($page, $start, $len); This worked to get me item 1 However, I'd like to loop through and get the other items too, and eventually the <p> elements also. I am trying to stay within the PHP structure. I was considering a while loop that would increase the pos of the next progressive $start by adding the $len of the previous effort, but I couldn't remember the correct methodology. Guidance and input please.
  6. @Psycho @gizmola Thanks for the info. Interesting points. The question arose as I was typing with some sloppy code. I've carefully played with the discussed concept and it seems to be safe from problems for the limited use I've assigned it (although I did stumble onto an occasional oddity, but I realized the source was off my own diabolical creation and was able to contain it.) I'll keep you updated. Now I have a new issue to post. LOL
  7. Understood. I thought it was a little odd, which is why I asked the question. Are there any restrictions? Can a key start with a dot/period? A number? Even a character??
  8. While solving my issue from yesterday, I discovered that I can use an associative array with key names that have space. ie: $arr['i never knew'][0] Normally, I would have used underscores to fill spaces OR removed them completely. Is this a new feature that I stumbled upon? Is it safe to use? Are there drawbacks?
  9. Used the suggested tools and discovered my problem. The array variable was inside a string. Apparrently this negates the array tendencies once they are lost.
  10. ** Recent development ** I modified my approach and got a response //At first $ingredients = ["sugar", "flour", "water"]; $spec_recipe = ["apple", "cinnamon", $ingredients]; echo $spec_recipe[2]; RESULT: Array echo $spec_recipe[2][0]; RESULT: A (assuming first letter of Array) Now I altered the variable to specify an element $ingredients = ["sugar", "flour", "water"]; $spec_recipe = ["apple", "cinnamon", $ingredients[0] ]; echo $spec_recipe[2]; RESULT: sugar I suppose this is something, but I want the array to become available through this variable so that I can address the full array contents. What am I missing?
  11. @mac_gyver Save as my initial info in this question. Both direct access efforts and print_r: [6] => Array The data is not getting pulled by the variable, yet it knows there's an array present. Not sure if exact version, but current.
  12. @gw1500se No luck. In not sure if it matters that this variable is stuck into a sub array. This started out working well with single words or phrases. But when I incorporated an array to provide those words and phrases, it went bonkers. I felt that the array structure was getting cluttered and that variables would help organize it. Was I wrong?
  13. I'm trying to include an array inside of a different array, but having trouble reaching the data. $ingredients = ["sugar", "flour", "water"]; $spec_recipe = ["apple", "cinnamon", $ingredients]; echo $spec_recipe[2]; RESULT: Array echo $spec_recipe[2][0]; RESULT: A (assuming first letter of Array) How do I move this info correctly so that it's accessible?
  14. Never mind. Reapplied the logic and resolved the issue.
  15. It seemed like a simple idea for a snowy day, but now I've lost my way in the forest. The plan: I have a landing page that will connect to either page 1, 2, or 3. These pages all flow to page A. On page A, I decided (big mistake) to say "I hope you enjoyed visiting our page X." My idea was to create a $_SESSION['page] variable in each of pages 1,2,3 and provide the appropriate value accordingly. When a user why to page A, the variable would follow and populate the sentence çorrectly. If they went to page A directly or from the landing page, the variable would be blank bc there is no session value associated. My first steps seemed to be okay, but then I couldn't clear the session from the landing page. Is my implementation completely off?
  16. Sounds like good advice, but is there any real reasoning (other than that JS can be turned off)?
  17. The title says it all. I have a few instances for redirecting to another webpage with a click. Then I got to thinking (always leads to trouble), is there a difference or benefit between using: 1) a plain old HTML<a> 2)window.location in the <> tags 3) creating a JavaScript listener
  18. It seems that the auto increment for the ID prohibits use of an asterisk (to SELECT * and use everything EXCEPT the ID in the insert). Is there a lazy workaround (that's worthwhile)?
  19. Ok, it seems to be working now (so I can build out on it). To be truthful, I had tried that (you taught me well) but your confirmation lead me to a different dumb mistake, as I was toying with this piece of code at the bottom of a PHP page and neglected to remove the line containing: mysqli_close($con) Therefore, there was no connection. Hence, failure. What sort of PHP could I use to alert me and prevent this type of issue. Note: I check the connection at the top of the page using if($con === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } but it doesn't trigger (with the terminated connection in place) because $con is still valid. Thanks for the help.
  20. I'm trying to copy a row so that I can later update within a given table. I'm not sure if there's a syntax error or rule error, or a missing piece but this code is not doing the job. $sql = "INSERT INTO $table (id, company_name) SELECT id, company_name FROM $table WHERE id = 26"; The table has auto increment ID, but the many alterations that I've made have failed. Guidance or solution, please. Thanks.
  21. I've tried a few iterations but cannot get the correct syntax $sql = "UPDATE $table SET item=? WHERE id<10 id = LAST_INSERT_ID() ORDER BY id ASC LIMIT 1; SELECT LAST_INSERT_ID();"; //and then $last_id = mysqli_insert_id($conn); echo "Last inserted ID is: " . $last_id; Where is my mistake?
  22. @mac_gyver I've gathered most of the "it can be done" from my web searches. I need an example (preferably in procedural PHP) of HOW to do it. I have made a few attempts, but none are producing results.
  23. As a follow-up to my recent post to determining the AFFECTED ROWS after an update to a table, I am now interested in obtaining the row's ID. I previously obtained HOW MANY rows were affected. Now I want to know WHICH ROWS. In actuality, I'm using LIMIT 1 in my update, so I'm looking for a PHP echo of the row ID (so that I can refer back to it). I've seen some examples in SQL that involve a psuedo-INSERT, but they don't offer a PHP transition (procedurally) to accomplish an echo confirmation. Guidance or code solutions appreciated.
  24. I couldn't agree more! But, @maxxd , are you encouraging me to post even more questions? LOL I've certainly learned and overcome PLENTY of obstacles here. But moving deeper into the pool may be a step further than I'm ready to "bind" before being fully "prepared" (see what I did there 🙂 ). TBH, I nearly fell overboard when mySQLi became mandatory But hey, ya never know. Thanks for the support.
  25. @maxxd Thanks, I think I've got the prepared statement accomplished. I "understand" procedural. The "shorthand" of PDO gets me confused and lost. I have the same problem moving from vanilla JavaScript to jQuery. If you have a remedy (or therapy.. LOL) that will help me overcome these issues, please share. And please keep this confidential. Just between us. I don't want my personal information on the internet. *wink*
×
×
  • 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.