Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. To dynamically create multiple instances of your emoji selector and text area pair, you can use a loop to generate unique IDs for each pair and then initialize the event listeners accordingly. <!DOCTYPE html> <html> <head> <title>Dynamic Emoji Selector</title> </head> <body> <!-- Add a container where the emoji selector and text area pairs will be added --> <div id="emojiContainer"></div> <!-- Your original emoji selector and text area template --> <select id="emojiSelectTemplate"> <option value="">Select a kaomoji</option> </select> <textarea name="comment_text_template" class="comment_text" rows="2" cols="40" placeholder="Type comment reply here." required></textarea> <script> document.addEventListener('DOMContentLoaded', function() { const emojis = [ '(・ω・)', '(´・ω・`)', '(。♥‿♥。)', 'ヾ(⌐■_■)ノ♪', '(╯°□°)╯︵ ┻━┻' ]; // Get a reference to the emoji container const emojiContainer = document.getElementById('emojiContainer'); // Loop to create multiple instances const numInstances = 30; // Change this to the number of instances you need for (let i = 0; i < numInstances; i++) { // Clone the template elements const emojiSelect = document.getElementById('emojiSelectTemplate').cloneNode(true); const inputText = document.getElementsByClassName('comment_text')[0].cloneNode(true); // Set unique IDs for each instance emojiSelect.id = 'emojiSelect' + i; inputText.id = 'comment_text' + i; // Append cloned elements to the container emojiContainer.appendChild(emojiSelect); emojiContainer.appendChild(inputText); // Populate the select dropdown with emojis emojis.forEach(emoji => { const option = document.createElement('option'); option.value = emoji; option.text = emoji; emojiSelect.appendChild(option); }); // Event listener for emoji selection emojiSelect.addEventListener('change', function() { const selectedEmoji = this.value; if (selectedEmoji) { inputText.value += selectedEmoji; this.selectedIndex = 0; // Reset dropdown to default option after selection } }); } }); </script> </body> </html> In this modified version: I've added a <div> with the id emojiContainer where the dynamic instances of emoji selectors and text areas will be added. The original emoji selector and text area are now considered as templates (with id="emojiSelectTemplate" and class="comment_text" respectively). Inside the loop, I clone the template elements, set unique IDs for each instance, and then append them to the container. Best Regard Danish hafeez | QA Assistant ICTInnovations
  3. To achieve this without dynamically building a query with OR conditions, you can use a JOIN with a LIKE condition. SELECT DISTINCT d.* FROM data d JOIN groupareas ga ON d.areaId = ga.areaId JOIN areas a ON ga.areaId = a.areaId JOIN ( SELECT groupId, GROUP_CONCAT(areaPath) AS areaPaths FROM groupareas ga JOIN areas a ON ga.areaId = a.areaId GROUP BY groupId ) AS grouped_areas ON ga.groupId = grouped_areas.groupId WHERE CONCAT(d.areapath, '\\') LIKE CONCAT(grouped_areas.areaPaths, '\\%') AND ga.groupId = ?; The inner subquery (grouped_areas) fetches all the area paths associated with each group and concatenates them into a single string using GROUP_CONCAT. Each group's area paths are grouped by the groupId. The main query then joins the data table with groupareas, areas, and grouped_areas subquery. It uses CONCAT to compare each areapath from the data table with the concatenated area paths of the group. The LIKE condition checks if the areapath of each data record starts with any of the concatenated area paths for the group. This effectively matches all records whose areapath is a child of any of the defined area paths for the group. Finally, the DISTINCT keyword ensures that each record is only returned once, preventing duplicates. Best Regard Danish Hafeez | QA Assistant ICTInnovations
  4. Yesterday
  5. the correct way of including code in the forum is to use the menu's <> button.
  6. this is a parse/syntax error. to get php to report and display parse/syntax errors, you must have the php error related settings in the php.ini on your system, so that they are in effect before your php script is parsed, tokenized, and executed. error_reporting should ALWAYS be set to E_ALL. you cannot successfully set display_startup_errors in your code because php has already started by the time your code is running. during development, yes, you should have display_errors set to ON (or 1, e.g. a true value.) when running code on a live/public server, you should have display_errors set to OFF (or 0, e.g. a false value) and log_errors should be set to ON. the only database exceptions you should catch and handle in your code are for user recoverable errors, such as when inserting/updating duplicate or out of range user submitted data values. in these cases, the catch logic should test the error number and setup a message for the user letting them know what was wrong with the data that they submitted. for all other error numbers, just rethrow the exception and let php handle it. for all other query types and all other database statements that can fail, do nothing in your code and let php handle any database exception. when you let php catch and handle the database exception, php will 'automatically' display or log (using the php error related settings) the actual error information for you via an uncaught exception error.
  7. Whenever I use the CODE and /CODE tags to surround my code I always have to go and edit my post to re-format the code as actual tabs seem to get added in at seemingly random places. I don't have any tabs in my code as I only ever use spaces and two spaces per intent level.
  8. FIXED! Somehow my try...catch section, the die() statement I've passed it two parameters as the . to concatenate strings turned into a comma. No idea how that happened but I've changed it to a . and it's all now working perfectly. Although I have no error message appear telling me there was a problem with it.
  9. I've got XAMPP installed onto two machines. This (my primary machine) is running Manjaro and my laptop behind me is running Mint. I've rebooted my laptop and I can no longer find any application in the launch menu (Start menu on Windows) called LAMPP or XAMPP. Tried typing LA and XA and get nothing returned. How do I launch it please?
  10. I have the following code and yesterday this was working and now I get nothing sent to my browser... <?php ini_set('display_errors','1'); //only during development ini_set('display_startup_errors','1'); //only during development error_reporting(E_ALL); //only during development $options=[ PDO::ATTR_EMULATE_PREPARES => false, // turn off emulation mode for "real" prepared statements PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //turn on errors in the form of exceptions PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, //make the default fetch be an associative array ]; try { $pdo=new PDO("mysql:host=localhost;dbname=polthouse",'root','',$options); } catch (PDOException $e) { die('Connection failed: ',$e->getMessage()); } phpinfo(); ?>
  11. the limitation is probably in the get or set session methods or in the code displaying or processing the cart. this code is overly complicated. the only data that should be stored in the cart is the quantity and the item id (itemCode) should be used as the cart's array index. once you index the data using the id, you can directly find, test, or reference the data. no looping required. the following is the only code needed to add an item to the cart once you do this - // add to cart code if(!isset($cartItems[$_POST['ItemCode']])) { // if an item isn't in the cart, add it with zero quantity $cartItems[$_POST['ItemCode']] = 0; } // add the submitted quaitity to the cart $cartItems[$_POST['ItemCode']] += $_POST["ItemQty"];
  12. I'm looking for a way to perform multiple LIKE conditions on a field without a string of ORs. In a perfect world, MySQL would support something such as WHERE field LIKE (SELECT matchField FROM table WHERE . . . ) Here is my situation: My records in a table we'll call "data" all have a value called an AreaPath which is essentially a hierarchical list. This value is coming from the source data and I have no control over it. Many items will have the same area path. Here is a mock example of what the data might look like: Cars\Autos\Peugeot Cars\Autos\Peugeot\ Peugeot 404\ Cars\Autos\Peugeot\ Peugeot 404\Coupe\1952 Cars\Autos\Peugeot\ Peugeot 405\ Cars\Autos\Toyota Food\Bread\Croissant Food\Pasta\Spaghetti During an import of the data, I'll be creating/updating a table called "areas" with all the unique area paths. areaId | areaPath 1 Cars\Autos\Peugeot 2 Cars\Autos\Peugeot\Peugeot 404\ 3 Cars\Autos\Peugeot\Peugeot 404\Coupe\1952 4 Cars\Autos\Peugeot\Peugeot 405\ 5 Cars\Autos\Toyota 6 Food\Bread\Croissant 7 Food\Pasta\Spaghetti In my database, I have a table called "Groups" where a user can define a group by name: groupId | groupName 9 French Then, the user will be able to define area paths that will be associated with the group (table groupareas). But, the user does not have to define all the distinct area paths only the top levels. For example, if the user selects the area path "Cars\Autos\Peugeot", then it would encompass that specific area path and ALL paths below it (e.g. "Cars\Autos\Peugeot\Peugeot 404\", "Cars\Autos\Peugeot\Peugeot 505\", "Cars\Autos\Peugeot\Peugeot 404\Coupe", etc.) groupAreaId | groupId | areaId 1 9 2 2 9 6 The above example would define the group "French" to include the area paths of "Cars\Autos\Peugeot" and "Food\Bread\Croissant". So, what I need to do is be able to dynamically query all the records that would belong to a particular group based on that data. Like I said above, in a perfect world I could do something like this SELECT * FROM data WHERE areapath LIKE ( SELECT CONCAT(areaPath, '%') FROM areas JOIN groupareas ON areas.areaId = groupareas.areasId AND groupareas.groupId = ? } But, that won't work. So, my fallback solution would be to run two queries. First query the area paths associated with a group and then programmatically build a query with OR conditions. SELECT CONCAT(areaPath, '%') FROM areas JOIN groupareas ON areas.areaId = groupareas.areasId AND groupareas.groupId = ? Then iterate through the results to build this. Note: I would have to also convert the backslashes. SELECT * FROM data WHERE ( areapath LIKE "Cars\\Autos\\Peugeot%" OR areapath LIKE "Food\\Bread\\Croissant%" ) While that would work, I will be running lots of different queries against the data to run various reports on different groups. Having to programmatically create the queries will be inefficient. I'm looking to see if there is a way to pull all the records for any "group" in one query by just changing the groupID. I hope this all makes sense.
  13. Ive modified the Simple PHP Shopping Cart from the phppot site but for some reason when the cart reaches 19 items it wont add anything else to it and i dont know why. Is their a limit within php how long a session array can be? Here is the code that adds each item to the array $cartItems = Session::get("cart_item"); $itemArray = array( 'ItemDesc' => $_POST["ItemDesc"], 'ItemCode' => $_POST["ItemCode"], 'ItemQty' => $_POST["ItemQty"], 'ItemAmount' => $_POST["ItemAmount"], 'ItemTotalAmount' => ($_POST["ItemQty"] * $_POST["ItemAmount"]), 'IdSupplier' => $_POST["IdSupplier"]); if(!empty($cartItems)) { if(in_array($itemArray["ItemCode"],array_keys($cartItems))) { foreach($cartItems as $k => $v) { if($itemArray["ItemCode"] == $k) { if(empty($cartItems[$k]["ItemQty"])) { $cartItems[$k]["ItemQty"] = 0; } $cartItems[$k]["ItemQty"] += $_POST["ItemQty"]; } } } else { $cartItems[] = array_merge($cartItems,$itemArray); } } else { $cartItems[] = $itemArray; } Session::set("cart_item", $cartItems); $counter = count(Session::get("cart_item")); Any help or suggestions would be greatly appreciated
  14. Nope, a decimal point counts as an operator (apparently). Supposedly it really is just the problem at face value: those four numbers, each used once, and as many add/subtract/multiply/divide operations (and parentheses) as you want. The way that latter point is phrased is unusual. "Unlimited supply", but you'd only ever need three... So you'd think there's a trick there, but it specifically states you have to use them as binary operators.
  15. Does this count? 7 * 6 * 1 * .5
  16. 22 is easy (5 - 1) * 7 - 6 but wouldn't an id card that had an age entry like that look just a lttle suspicious? eg Age : (5 - 1) * 7 - 6 I'll keep trying for 21.
  17. Could swear I had a book with these sorts of puzzles but I can't find it. So I'm looking through the internet for a good source to post - not original, but it is something - and I find this one: I can't solve it. Even ran a quick script to try every possible combination of ((# _ #) _ #) _ # and nothing works. So I'm figuring there must be some trick in the phrasing, except I'm not seeing a loophole in there: "each number exactly once" using the "binary operations" of "addition, subtraction, multiplication, and division". (And in fact, creating operators like negation and exponent still isn't enough to get a solution.) Non-answer: if the goal is to be legally an adult then coming up with 22 would be fine too.
  18. Last week
  19. If you're not running this in Docker, or perhaps even if you are, it sounds like your database configuration wasn't set up properly. Check the hostname you have it using.
  20. Hi all. I encountered a problem in my laboratory work on web technologies. When I use the php artisan migrate command I get the following error. Illuminate\Database\QueryException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for db failed: nodename nor servname provided, or not known (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'db' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name) at vendor/laravel/framework/src/Illuminate/Database/Connection.php:813 809▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 810▕ ); 811▕ } 812▕ ➜ 813▕ throw new QueryException( 814▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 815▕ ); 816▕ } 817▕ } +48 vendor frames 49 artisan:13 Illuminate\Foundation\Application::handleCommand(Object(Symfony\Component\Console\Input\ArgvInput)) I am using ddev. MacOS. I've already tried everything and don't know how to fix it. Who knows how to fix this?
  21. Is that missing one? The version I know has 11 "had"s. Though 10 works too, it's just changing which boy was correct. There's also the classic "buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo" (needs punctuation and capitalization), but that can totally be stretched out further - like pretty easily to "buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo buffalo". I should go looking for some puzzles too...
  22. 'til now they have been mathematical so here's one that's purely grammatical Q4 Correctly punctuate this sentence so that it makes sense the two boys had written very similar essays but peter where paul had had had had had had had had had had been preferred by the teacher
  23. Welll done. I knew you'd do it. Hint for others:
  24. That wasn't the answer? No way, that totally was the answer Then I'm thinking 11 twigs.
  25. Your foreach() loop expects several items and that each will be put into $row as you loop through. But get(cart_item) only returns a single item so when you use foreach() you are looping through its properties Try $row = Session::get("cart_item"); echo <<<ITEM <tr> <td width="70"><center>{$row['ItemCode']}</center></td> <td>{$row['ItemDesc']}</td> <td width="70"><center>{$row['ItemQty']}</center></td> <td width="70"><center>{$row['ItemAmount']}</center></td> <td width="70"><center>{$row['ItemTotalAmount']}</center></td> </tr> ITEM;
  26. Thanks you so much, i couldn't see the wood for the trees i'd put $cartItems = $itemArray; instead of $cartItems[] = $itemArray; before setting the session Session::set("cart_item", $cartItems);
  27. Sorry am getting PH FLEXI FRAME EXTENDER FRAME 370373 1 210.92 210.92 So why is it putting everything on a new row!
  1. Load more activity
×
×
  • 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.