Jump to content

kicken

Gurus
  • Posts

    4,708
  • Joined

  • Last visited

  • Days Won

    180

kicken last won the day on August 23

kicken had the most liked content!

3 Followers

About kicken

Contact Methods

  • Website URL
    http://aoeex.com/

Profile Information

  • Gender
    Male
  • Location
    Bonita, FL
  • Age
    36

Recent Profile Visitors

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

kicken's Achievements

Prolific Member

Prolific Member (5/5)

738

Reputation

170

Community Answers

  1. What you will see if you open that PHP file in a text editor such as Notepad.
  2. We can't help unless you share the source code of the script. All I could say at this point is the script outputs a 0 byte image.
  3. AI tools are usually pretty good for getting started with a simple task like this. I googled the relay board you mentioned and found a PDF that lists the data required to turn the relays on or off. I feed that into ChatGPT and asked it to describe the protocol to get an understanding of it. I then asked it to generate a web form using PHP that can be used to turn the relays on or off. <?php // relay_control.php // === Function to build command === function relayCommand(int $relay, bool $state): string { $header = 0xA0; $relayByte = $relay & 0xFF; $stateByte = $state ? 0x01 : 0x00; $checksum = ($header + $relayByte + $stateByte) & 0xFF; return pack('C4', $header, $relayByte, $stateByte, $checksum); } // === Handle form submission === $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $relay = intval($_POST['relay'] ?? 1); $state = ($_POST['action'] === 'on'); $cmd = relayCommand($relay, $state); $hexCmd = strtoupper(bin2hex($cmd)); // Example: write to USB device (uncomment when you know the device path) // $fp = fopen('/dev/ttyUSB0', 'wb'); // if ($fp) { // fwrite($fp, $cmd); // fclose($fp); // } $message = "Relay $relay " . ($state ? 'ON' : 'OFF') . " → Command: $hexCmd"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Relay Control</title> <style> body { font-family: Arial, sans-serif; padding: 20px; } form { margin: 20px 0; } select, button { font-size: 16px; padding: 5px 10px; margin: 5px; } .msg { margin-top: 15px; font-weight: bold; } </style> </head> <body> <h1>LCUS-8 Relay Control</h1> <form method="post"> <label for="relay">Relay number:</label> <select name="relay" id="relay"> <?php for ($i = 1; $i <= 8; $i++): ?> <option value="<?= $i ?>"><?= $i ?></option> <?php endfor; ?> </select> <button type="submit" name="action" value="on">Turn ON</button> <button type="submit" name="action" value="off">Turn OFF</button> </form> <?php if ($message): ?> <div class="msg"><?= htmlspecialchars($message) ?></div> <?php endif; ?> </body> </html> Sounds like a project that you could do with a raspberry pi computer + the relay board. Might be able to go even simpler if you didn't need to host the control interface on the device itself and instead just communicated with it over the network or a serial port.
  4. It doesn't sound like you are looking ahead into other rooms, just looking at the stock levels of all the supplies in the current room. Ex: foreach ($roomList as $room){ $ivStockLow = $room['meds']['IV'] < 2; $pillStockLow = $room['meds']['pill'] < 4; $syrupStockLow = $room['meds']['syrup'] < 8; $ivOrder = max(0,2-$room['meds']['IV']); $pillOrder = max(0,4-$room['meds']['pill']); $syrupOrder = max(0,8-$room['meds']['syrup']); if ($pillStockLow){ $ivOrder=10; } else if ($syrupStockLow){ $pillOrder=10; } } Determine whether each item is low first, then use that information to adjust the order amount later on. Add in whatever constraints you need for budget as well.
  5. In the documentation, it shows you the various options for the privilege level that you can specify. The | separates the possible options and can be read like or. So for the priv_level portion of the GRANT statement you can use either "*" (meaning default database), "*.*" (meaning all databases), "db_name.*" (meaning the entire database db_name), "db_name.tbl_name" (meaning table tbl_name in database db_name), "tbl_name" (meaning table tbl_name in the default database), or "db_name.routine_name" (meaning the routine routine_name in database db_name). Since you want to grant privileges on a specific database, you would use the "db_name.*" option when writing your grant statement. That means you'd write your grant statement like so: grant all on wordpress.* to 'webuser'@'host'
  6. Yes, See the documentation for the GRANT statement. The privilege level can be specified as: priv_level: { * | *.* | db_name.* | db_name.tbl_name | tbl_name | db_name.routine_name } So to set a privilege on an entire DB you would use the db_name.* syntax rather than the db_name.tbl_name syntax you are currently using.
  7. There is an example near the end of the documentation for last_insert_id. Something like this I am guessing. $sql = " UPDATE $table SET item=?, id=LAST_INSERT_ID(id) WHERE id<10 ORDER BY id ASC LIMIT 1; "; //and then $last_id = mysqli_insert_id($conn); echo "Last inserted ID is: " . $last_id;
  8. Use CREATE USER first to create the user account, then grant it the privileges it needs. create user 'webuser' identified by 'abc123'; grant all on wordpress.table to 'webuser'; Your first two grants failed because you are creating a new user. 'webuser'@'localhost' is different from 'webuser'@'host' specified in your create user statement. Your second two failed because you didn't specify a valid privilege type.
  9. If the form is not added until the radio button is changed, the your code adding the event listeners cannot be run until after the radio button is changed either. Alternatively, you add the event listener higher up in the DOM and check the element that triggered the event. For example: document.getElementById("div2").addEventListener("click", displayDate); function displayDate(e){ if (e.target.tagName !== 'INPUT'){ return; } alert('Trigger'); } You callback function is given an event object as it's parameter. That object has a property called target which is a reference to which DOM element triggered the event. Check that DOM element to see if it matches your criteria, in this case that it's an <input> element.
  10. Assuming your while loop is running more than once, you're duplicating your element IDs which results in invalid HTML. ID values must be unique within the document.
  11. Styles set on an element directly (such as through element.style or the style attribute) take precedence over any styles defined in a style sheet. It's best then to avoid setting styles directly and instead just add or remove a class from the element. You can add and remove multiple classes if needed to be able to target specific conditions. See my updated fiddle for an example.
  12. Use a multi-line closure and log the value. divs.forEach(d => { console.log(d); d.classList.remove('active'); }); If you just want to change some colors on click, you can probably do that without JavaScript at all. HTML: <div tabindex="-1">First div</div> <div tabindex="-1">Second div</div> <div tabindex="-1">Third div</div> The tabindex attribute lets you make the div focusable. Having the div focusable allows you to use the :focus css pseudo class. CSS: div { margin: 2rem; padding: 1rem; border: 2px solid #00F; } div[tabindex]:focus { background: #000; color: #fff; }
  13. Set your old timestamp variable to null when the game is started/restarted. this.oldTimeStamp = null; Then in your game loop function, check if it's null and if so store the provided timestamp. if (this.oldTimeStamp===null){ this.oldTimeStamp=timeStamp; } This way your game always starts out at 0 for seconds passed. Currently, your first iteration when the page loads is essentially random as it depends on how long it takes for the browser to run the first game loop after starting the page.
  14. Try adding the indent option.
  15. Formatting values should always be a last-step operation. You want to structure your code so the prices remain as numbers and you can do whatever operations on them you need to do, then only format them right before you display them, for example directly in your template if possible. $price1 = 30; $price2 = 74.99; $bundle = $price1 + $price2; //...anything else //When everything is done and you're ready to display echo getMoneyUSD($price1); echo getMoneyUSD($price2); echo getMoneyUSD($price3); Also, you should know that floating point math can lead to issues due to lack of precision. A common way to avoid these issues is to work with your prices as integers (ie, number of cents) then convert them to decimals as part of the formatting process. Alternatively, you could find a library for dealing with currency values that handles such issues for you.
×
×
  • 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.