Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 11/04/2022 in Posts

  1. Slightly different approach then. Store the category query results in an array. $stmt = $pdo->query("SELECT categoryID , categoryName FROM tbl_categories WHERE categoryActive = 1 ORDER BY categoryID "); $cat_options = []; /// store cat data in array foreach ($statement as $row) { $cat_options[$row['categoryID']] = $row['categoryName']; } // main loop here while ($row = $stmt->fetch()) { echo "<select name='categoryID' class='select200px' required> <option value=''>Select...</option>"; foreach ($cat_options as $id => $cat) { $sel = $row['categoryID'] == $id ? 'selected' : ''; echo "<option $sel value='$id'>$cat</option>"; } echo "</select>"; }
    1 point
  2. I don't know Postgresql. The problem you're going to have is that 1.10 is less than 1.9, In fact, it is equal to 1.1. If the Cast-Substribg works (again, I don't know Postgres), you should do it twice to split the version number. And order by the two values. Something like this CAST ( SUBSTRING ( movies.title FROM '#(\d+)\.\d+' ) AS INT ) AS major, CAST ( SUBSTRING ( movies.title FROM '#\d+\.(\d+)' ) AS INT ) AS minor ... ORDER BY major, minor You can use Integer now, instead of Decimal.
    1 point
  3. Sure. First, as mentioned before this is not SMTP, so all the SMTP_* constants you are using are either the wrong values or incorrectly named. Either make new IMAP settings to use or rename your constants. Second, this is based on some code I have that checks an email account for a one-time-password code so I can login and download data from a site. <?php //Example parameters. $host = '{imap.example.com:993/ssl/readonly}'; $mailbox = 'otp@example.com'; $password = ''; function getSecurityCode(string $host, string $mailbox, string $password) : ?string{ $authCode = null; $startTime = time(); do { sleep(5); $handle = imap_open($host, $mailbox, $password, OP_READONLY, 5); if (!$handle){ throw new RuntimeException('Unable to open mailbox'); } $messageList = imap_sort($handle, SORTDATE, 1); foreach ($messageList as $messageNumber){ $messageInfo = imap_fetch_overview($handle, $messageNumber)[0]; if (isOTPEmail($messageInfo) && isReceivedInLast5Minutes($messageInfo)){ $authCode = extractAuthCode(imap_body($handle, $messageNumber)); break; } } imap_close($handle); } while (!$authCode && time() - $startTime < 300); return $authCode; } function isOTPEmail(stdClass $messageInfo) : bool{ if (!isset($messageInfo->subject)){ return false; } return stripos($messageInfo->from, 'donotreply@example.com') !== false && stripos($messageInfo->subject, 'One-Time Passcode') !== false; } function isReceivedInLast5Minutes(stdClass $messageInfo) : bool{ if (!isset($messageInfo->date)){ return false; } $date = DateTime::createFromFormat(DateTimeInterface::RFC2822, $messageInfo->date); if ($date === false){ $date = DateTime::createFromFormat(DateTimeInterface::RFC2822 . ' (\G\M\T)', $messageInfo->date); } if ($date === false){ return false; } $now = new DateTime('', $date->getTimezone()); $now->sub(new DateInterval('PT5M')); return $date > $now; }
    1 point
  4. if you were doing this for real, where the price can change over time, the pricing would be stored in a related table, associated back to the token rows through the token's id, with a token_id, price, and effective start and effective end datetime columns. the point of the id column in this table is to assign a token id (auto-increment integer primary index), that would be stored in any related data table. this is the value that the form would submit for the selected token and would be stored in the usertoken table, not the token name. the balance is a derived value. you would not maintain the balance as a single value in a column, but would instead calculate it when needed. to do so, you need an account(ing) table, with a separate row inserted for each deposit/withdrawal that affects the account balance. also, the full name should be stored, using two columns, e.g. first_name, and last_name, so that you can uniquely distinguish between and search for people by name, e.g. is someone Ross Martian or Martian Ross? the account(ing) and usertoken table would use the id value from the users table, to related any stored data back to the correct user. this table should contain all the who, what, when, where, and why information about the purchase. the who would be the user_id of the buyer. the what would be the token_id, quantity, and purchase price (if you have a separate table for the pricing, you don't need this value). the when would be the datetime of the purchase. the where would only apply if there's a location associated with the purchase. the why would be a status/type value or memo field describing the reason for the purchase. this table doesn't need the account number, as that is defined in the users table and is known based on the user id. also, the totalbuy is a derived value that isn't stored. it is calculated when needed using the quantity and the purchase price (or the separately stored price at the datetime of the purchase.) the discount amount should be calculated and inserted as a separate row, in a related discount/interest accounting table, related back to the usertoken through the id in the usertoken table. you must do this as a single 'atomic' operation, in one query. the way to do this is use the query technique shown in this thread - https://forums.phpfreaks.com/topic/315532-avoid-appointment-conflict where you have an INSERT ... SELECT query that will only insert a new row in the usertoken table if the where clause calculates if the user's current balance - by summing the user's accounting rows, discount/interest rows, minus the user's existing token purchase amounts, is greater then or equal to the total amount of the submitted purchase. and just to clarify, the only two values submitted from the form should be the selected token id and the quantity. everything else should use values that only exist on the server.
    1 point
  5. The first question I would have for you, is do you have a solid "non-expert" understanding of html5 and css? That is what I would highly recommend to get down 1st. This is a good free course to go through, that is all done interactively in the Scrimba environment: https://scrimba.com/learn/introhtmlcss It's taught by Kevin Powell who is one of the better known css teachers I know of, and has an extensive set of video tutorials on youtube. Before you go further down any path, I would recommend you watch this video, which really helps you get an idea of what these different techs provide you from a design/UI standpoint: If you watch enough of this you'll get to the point where he compares some options (vanilla css, vs tailwind vs Material UI (MUI) vs Bootstrap, and declares: "Yeah Don't use Bootstrap. It's 2022 and you know better!" Nonetheless, this is a professional design guy who has worked for various well known companies and is very experienced, so I won't be an absolutist about this, but you should at least go into whatever phase of learning you are entering knowing more about this. I personally use Bootstrap every week for a client I work for, and I would certainly love to be able to move on from it now, but I'm stuck with a giant code base that is tightly integrated with it. At least do your research. Absolutely you should be using the latest version if you do use it. I have found that it is actually pretty easy to use in most cases, however this guy has a complete course on it, and most of his videos are really good: One thing to keep in mind is that Bootstrap does have places where to really take advantage of some of the widgets, you also need to have a working understanding of javascript, in order to integrate it with what you are doing. That is going to be true of many other css frameworks and approaches. It also needs to be said, that whether or not you should be using Bootstrap is a significant question, as there are other css frameworks that have become extremely popular, most notably Tailwind CSS. There are a number of other popular css frameworks, many of which are better suited to customizing the look and feel of things, or have a philosophy that is a bit more modern than what bootstrap has (given that Bootstrap is pretty old at this point, even though it has been updated). Here's an intro to tailwind and a complete course by a guy who has a lot of courses on Udemy, and was actually paid to make a professional level course on Tailwind that is again free on youtube. It is project based, but only one project in this case. If you like Tailwind as an approach then you probably want to look at TailwindUI and/or DaisyUI which build upon Tailwind and are closer to what you would get with much of Bootstrap.
    1 point
  6. Knowing the fundamentals of something is different from knowing how to apply them. That works for everything: speaking a language, driving a car, cooking a dinner... What you've learned is the fundamentals but perhaps not how you actually use them. That said, website design is another thing by itself that takes some amount of learning. Learning how to use paint and a brush doesn't mean you can sell a painting. If you're a video person then see if you can find videos about the designing side of websites, not so much the syntax side.
    1 point
  7. Try $stmt = $pdo->query("SELECT * FROM care_plan_review WHERE reminder_date > CURDATE() + INTERVAL 7 DAY");
    1 point
  8. https://www.php.net/print_f You don't need to select the same column twice. The %s in the print_f format argument are placeholders for the string variables ($row['type_chocolate']) mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $mysqli = mysqli_connect("localhost", "root", "P-11fl32fg14", "cocoa"); $query = "SELECT type_chocolate FROM type_chocolate"; $result = mysqli_query($mysqli, $query); while ($row = mysqli_fetch_assoc($result)) { printf("<a href='cacau_type_chocolate.php?type_chocolate=%s'>%s</a>", $row['type_chocolate'], $row['type_chocolate']); }
    1 point
  9. Please stop posting your code on a single line. It's ****ing annoying.
    1 point
  10. I removed the passwords from your posts. You can do the reformatting yourself if you want people to read them. You do seem to be connecting to the DB server 3 ties in same file though - once is sufficient.
    1 point
  11. The column names in the query results wil be id_chocolate name_chocolate id_type_chocolate type_chocolate id_chocolate The tablename. prefixes are not part of them.
    1 point
  12. foreach(array_keys($matches[1]) as $key) { echo "SKU number {$matches[1][$key]} costs {$matches[2][$key]}<br>"; }
    1 point
  13. I may be reading it wrong but it looks to me that you are allocating the same id (ie $index) to the linkTree div and the linkSimilar tree.
    1 point
  14. the following is a 'tricky' example of INSERTing data that satisfies a maximum count of rows - $query = "INSERT INTO team_members (team_id, staff_id, stafftype) SELECT -- the following values being SELECTed are the actual data values to insert ?,?,? FROM DUAL -- dual is an allowed dummy table name to satisfy the FROM ... WHERE syntax WHERE (SELECT COUNT(*) FROM team_members WHERE team_id = ? AND stafftype='leader') < 1 -- insert the data if the WHERE (subquery count) < 1 is TRUE"; $stmt = $pdo->prepare($query); $stmt->execute([$team_id, $staff_id, $stafftype, $team_id]); if($stmt->rowcount()) { echo "A leader row was inserted for team_id: $team_id, staff_id: $staff_id<br>"; } else { echo "A leader already exists for team_id: $team_id<br>"; } this example was to insert a maximum of one 'leader' row per team id. you would change it to insert a maximum of two rows per datetime appointment slot. because this uses a single query to both get a count of the number of existing rows and insert a new row, it will work correctly for multiple concurrent instances of your script.
    1 point
  15. DOM ids must be unique. you basically have the same problem (and solution) as in this recent thread - https://forums.phpfreaks.com/topic/315508-php-and-javascript-with-mysql-copy-button/
    1 point
  16. As basic as it gets... <!DOCTYPE html> <html lang="en"> <head> <title>Sessions &amp; Terms</title> <meta charset="utf-8"> <script type='text/javascript'> function showDiv() { let thediv = document.getElementById("mydiv") if (thediv.style.display == "block") { thediv.style.display = "none" } else { thediv.style.display = "block" } } </script> <style type='text/css'> #mydiv { display: none; } </style> </head> <body> <button onclick='showDiv()'>Show Div</button> <br> <div id='mydiv'> <h1>Hello, world</h1> </div> </body> </html>
    1 point
  17. $sku = array( '1234', '5678', '4444', '2222', '9393', '1111', '8689' ); foreach(array_chunk($sku,5) as $chunk) { $qs = '&SKU=' . implode('&SKU=',$chunk); // examine the result echo $qs . '<br>'; }
    1 point
  18. If you follow requinix's advice and make the constructor private in the first code sample it's a textbook example of the Singleton pattern. While there was a period a few years ago that people railed against using Singletons, the furor seems to have died down recently. In my experience, 90 percent of the time it's perfect for things like setting up database connections.
    1 point
  19. FYI, if you're using Mysql 8.0 series you can simplify the query by using the window function. One of rank, dense_rank, or row_number would probably give you what you want. For example: SELECT name , total_received , total_donated , rank() over (ORDER BY total_received DESC, total_donated ASC) as the_rank FROM donation rd1 WHERE total_participant = 1 ORDER BY the_rank; | name | total_received | total_donated | the_rank | | ------- | -------------- | ------------- | -------- | | Dasher | 500 | 250 | 1 | | Cupid | 400 | 370 | 2 | | Prancer | 400 | 370 | 2 | | Comet | 380 | 370 | 4 | | Dancer | 200 | 510 | 5 | | Vixen | 100 | 200 | 6 | | Donner | 100 | 510 | 7 | If you're not on Mysql 8.0, you'll have to stick with Barands way.
    1 point
  20. Probably you should talk to the company hosting the API as it seems your request is going through fine so if there's a problem it's likely with the data you are sending not being what they expect. They are the only ones that can really tell you for sure if there is a problem with the data. If I had to take a guess, it would be that you seem to be trying to post multiple records when they probably only expect one. If you decide you're query string, you'll see you are posting data like this: 0[id]=6653&0[participacion]=6936&0[beneficio]=cine&0[fecha]=2018-04-16+14:41:59&0[promo]=33&1[id]=6654&1[participacion]=3318&1[beneficio]=payp That seems unusual to me. What would seem more likely is that you'd send one at a time with data such as this: id=6653&participacion=6936&beneficio=cine&fecha=2018-04-16+14:41:59&promo=33
    1 point
  21. explode() on the "|" to get the 3 main sections explode each of those on "=" to get the key and the values explode the values using ","
    1 point
  22. Brilliant, Sherlock! If you had taken the trouble to read the (old and already fixed) post you would have seen that it already uses the modulo operator.
    0 points
  23. Give all the divs a class of "mydiv". Then in the <style> section change #mydiv { display: none; } to .mydiv { display: none; } then they all start off hidden.
    0 points
  24. I pointed you at a thread containing a good PDO connection code example. In addition you had the RTFM option. Yet you still managed to come up with that rubbish - which is just a mysqli connection with the name changed.
    0 points
This leaderboard is set to New York/GMT-05:00
×
×
  • 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.