Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 02/19/2024 in all areas

  1. You've done the hard work already. Instead of calculating the product, store the selected array. <?php $primes = array(2, 3, 5, 7, 11, 13, 17, 19, 23); $combos = []; function getAllCombinations($arr, $n, &$combos, $selected = array(), $startIndex = 0) { if ($n == 0) { $combos[] = $selected; // $product = 1; // foreach ($selected as $prime) { // $pr[] = $prime; // $product *= $prime; // $pr[] = $prime; // } // echo "Product: $product\n"; return; } for ($i = $startIndex; $i < count($arr); $i++) { $selected[] = $arr[$i]; getAllCombinations($arr, $n - 1, $combos, $selected, $i + 1); array_pop($selected); // Backtrack and remove the element for next iteration } } getAllCombinations($primes, 4, $combos); echo '<pre>'; foreach ($combos as $com) { printf("%-35s = %5d<br>", join(' &times; ', $com), array_product($com)); // output numbers and product } ?> giving 2 × 3 × 5 × 7 = 210 2 × 3 × 5 × 11 = 330 2 × 3 × 5 × 13 = 390 2 × 3 × 5 × 17 = 510 2 × 3 × 5 × 19 = 570 2 × 3 × 5 × 23 = 690 2 × 3 × 7 × 11 = 462 2 × 3 × 7 × 13 = 546 2 × 3 × 7 × 17 = 714 2 × 3 × 7 × 19 = 798 2 × 3 × 7 × 23 = 966 2 × 3 × 11 × 13 = 858 2 × 3 × 11 × 17 = 1122 2 × 3 × 11 × 19 = 1254 2 × 3 × 11 × 23 = 1518 2 × 3 × 13 × 17 = 1326 2 × 3 × 13 × 19 = 1482 2 × 3 × 13 × 23 = 1794 2 × 3 × 17 × 19 = 1938 2 × 3 × 17 × 23 = 2346 2 × 3 × 19 × 23 = 2622 2 × 5 × 7 × 11 = 770 2 × 5 × 7 × 13 = 910 . . 5 × 17 × 19 × 23 = 37145 7 × 11 × 13 × 17 = 17017 7 × 11 × 13 × 19 = 19019 7 × 11 × 13 × 23 = 23023 7 × 11 × 17 × 19 = 24871 7 × 11 × 17 × 23 = 30107 7 × 11 × 19 × 23 = 33649 7 × 13 × 17 × 19 = 29393 7 × 13 × 17 × 23 = 35581 7 × 13 × 19 × 23 = 39767 7 × 17 × 19 × 23 = 52003 11 × 13 × 17 × 19 = 46189 11 × 13 × 17 × 23 = 55913 11 × 13 × 19 × 23 = 62491 11 × 17 × 19 × 23 = 81719 13 × 17 × 19 × 23 = 96577
    2 points
  2. $radint = mt_rand(1,33); $flip = mt_rand(1,2); $radint *= ($flip == 2) ? -1 : 1;
    1 point
  3. A couple of things: A way to mitigate the potential for sql injection (even if this is a backoffice tool) would be to cast the company id parameter to integer. $id = (int)$_GET['COMPANY_ID']; See Danish's post to you for some helpful improvements. Indeed you should use bound parameters as shown. With that said, it's not relevant to your script not working. Also omit the ending tag in your php scripts. ( ?> ) . Just scanning the code provided, it seems likely there is an issue with the database connection on the production server. You didn't provide that code but you probably aren't catching connection errors in dataconn/connection.php
    1 point
  4. It seems like your code is vulnerable to SQL injection, which could be causing issues, especially when running on the web server. It's always essential to sanitize user inputs to prevent such vulnerabilities. <?php if (isset($_GET['COMPANY_ID'])) { include('dataconn/connection.php'); // Prepare an update statement $sql = "UPDATE `MASTER_COMPANY` SET `COMPANY_STATUS`=? WHERE `COMPANY_ID`=?"; // Attempt to prepare the SQL statement if ($stmt = mysqli_prepare($con, $sql)) { // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "si", $PCompanySts, $id); // Set parameters $id = $_GET['COMPANY_ID']; $PCompanySts = "N"; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)) { session_start(); $_SESSION["delete"] = "Company Deleted Successfully!"; header("Location: /Companyindex.php"); exit(); } else { echo "Something went wrong"; } // Close statement mysqli_stmt_close($stmt); } else { echo "Error: Unable to prepare SQL statement."; } // Close connection mysqli_close($con); } else { echo "Company does not exist"; } ?> In this code: We're using prepared statements to safely execute the SQL query. User inputs are sanitized through parameter binding, reducing the risk of SQL injection. I've added exit() after the redirect header to ensure that no further code is executed after the redirection. Best Regard Danish Hafeez | QA Assistant ICTInnovations
    1 point
  5. Have you got php error reporting turned on? mysqli error reporting turned on? Have you checked error logs (on web server errors should be logged and not reported)?
    1 point
  6. It seems like you're trying to dynamically retrieve column names from the first loop and then use them to fetch corresponding data from the database in the second loop. However, you're facing issues with the data retrieval part. Let's correct the code: fputcsv($csvfile, $export_column_name_array, $delimiter); $stmt2 = $conn->prepare($sql_built_statement); //$stmt2->bind_param("ii", $company_id, $company_id); WILL ADD THIS LATER ONCE WORKING $stmt2->execute(); $result2 = $stmt2->get_result(); if($result2 != NULL){ // Retrieve data while($row2=$result2->fetch_assoc()){ // Initialize an empty data array for each row $data_array = array(); // Add data for each column foreach ($export_column_name_array as $value) { // Push data for each column into the data array $data_array[] = $row2[$value]; } // Write the data array to the CSV file fputcsv($csvfile, $data_array, $delimiter); } } fclose($csvfile); In this corrected code: We loop through each row of the fetched data and initialize an empty $data_array for each row. Within the row loop, we iterate through each column name from $export_column_name_array. For each column name, we fetch the corresponding data from the $row2 associative array and add it to the $data_array. After populating the $data_array with data for all columns, we write it to the CSV file using fputcsv(). The process repeats for each row fetched from the database until all rows have been processed. i hope This should correctly populate your CSV file with the data fetched from the database, using the dynamic column names obtained from $export_column_name_array. Best Regard Danish hafeez | QA Assistant ICTInnovations
    1 point
  7. Before I retired (approx 12 years ago) I regularly worked on a windows based intranet. I found the ADLDAP class a great tool. In fact the system admins used to ask me to create reports that they couldn't accesss via their Microsoft network tools. https://github.com/adldap/adLDAP
    1 point
  8. 1. If you use /s for regex delimiters (at the beginning and end) then any /s you want inside the regex have to be escaped. Look at what your original had. 2. What's the rest of the code?
    1 point
  9. Why would you use Javascript for this? It's okay to have the regex be multiple patterns. You don't, not necessarily, have to use a single capture group to get the one value you care about. youtube.com/shorts/(\w+)|youtube.com/watch\?v=(\w+)|youtu.be/whatever else Only one of $1 or $2 (or what you put in the "whatever else") will ever have a value. And do remember that "." matches anything, so "youtubexcom/short/blah" will match the above too.
    1 point
  10. As the data I was given has no data for RAGUL's empno in any tables (except usertable) I cannot verify any of my theories on what may be wrong. Also for branch 2 I have only this... +---------+---------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | month | name | CustomerTotal | CustomerActual | ProductionTotal | ProductionActual | MarketingTotal | MarketingActual | +---------+---------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | 2024-03 | Palanikumar B | | | | | 1 | | | 2024-02 | NAVEENKUMAR P | | | | | 1 | | +---------+---------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ For branch 5... +---------+------------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | month | name | CustomerTotal | CustomerActual | ProductionTotal | ProductionActual | MarketingTotal | MarketingActual | +---------+------------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ | 2024-02 | Nethaji.MK | | | | | 1 | | | 2024-02 | T.Anandakrishnan | | | | | 1 | | | 2024-02 | Sivanraj.A | | | | | 1 | | | 2024-02 | kannan.r | | | | | 1 | | | 2024-01 | thayyanayaki | 5 | 5 | 2 | 2 | | | | 2024-02 | thayyanayaki | 5 | 5 | 2 | 2 | | | | 2024-03 | thayyanayaki | 5 | 5 | 2 | 2 | 1 | | | 2024-04 | thayyanayaki | 5 | 3 | 2 | 1 | | | | 2024-01 | Vignesh.M | | | | | 1 | 1 | | 2024-02 | Vignesh.M | | | | | 1 | | | 2024-02 | N.Manikandan | | | | | 1 | | | 2024-02 | Dinesh.C | | | | | 1 | | +---------+------------------+---------------+----------------+-----------------+------------------+----------------+-----------------+ The previous queries (your and mine) would only report on whatever empno, branch and month values existed in the production table (the one that isn't LEFT JOINED). This version removes that reliance ... SELECT u.Month , Name , CustomerTotal , CustomerActual , ProductionTotal , ProductionActual , MarketingTotal , MarketingActual FROM ( WITH RECURSIVE allmonths (id, month) as ( SELECT 1, '2024-01' UNION ALL SELECT id+1, concat('2024-', lpad(id+1,2,'0')) FROM allmonths WHERE id < 4 ) SELECT empNo as empId , fname as name , month , ? as branch FROM usertable, allmonths -- WHERE role IN (4, 5) ) u LEFT JOIN ( SELECT count(*) as CustomerTotal , sum(VisitType = 'No Due' OR VisitDate != '') as CustomerActual , month , empid , branch FROM customerdata GROUP BY month,branch,empid ) ca ON u.month = ca.month AND u.empid = ca.empid AND u.branch = ca.branch LEFT JOIN ( SELECT count(*) as ProductionTotal , sum(MCubicmeter OR MHourmeter) as ProductionActual , month , empid , branch FROM production GROUP BY month, branch, empid ) pa ON u.month = pa.month AND u.empid = pa.empid AND u.branch = pa.branch LEFT JOIN ( SELECT count(*) as MarketingTotal , month , empid , branch FROM marketing_target GROUP BY month, branch, empid ) mt ON u.month = mt.month AND u.empid = mt.empid AND u.branch = mt.branch LEFT JOIN ( SELECT count(*) as MarketingActual , month , empid FROM marketing_data GROUP BY month, empid ) ma ON u.month = ma.month AND u.empid = ma.empid AND u.branch = mt.branch HAVING CustomerTotal OR CustomerActual OR ProductionTotal OR ProductionActual OR MarketingTotal OR MarketingActual ORDER BY u.empid, u.month;
    1 point
  11. Some are the result of running a query from the command line but most, particularly the relationhip diagrams, are hand-typed.
    1 point
  12. You can. The trick is use a code block for consistent charater widths. EG... +------------+-------------+--------+-------+ | Field Name | Field Label | Width | Order | +------------+-------------+--------+-------+ |First Name | Given Name | 6 | 1 | |Last Name | Surname | 6 | 2 | +------------+-------------+--------+-------+ I've used json columns in the past. I have found it a good alternative to the EAV data model (PITA). For example, in my sample data below there is a product table with 3 categories of product. Each category has different attribute: Membership - type, duration Book - author, title T-shirt = size, colour, style In a conventional relational table each attribute would require its own column and most of them would be empty. The json version uses a single column. The other table was for testing arrays and accessing and joining on array elements. You would store the metadata in your database to define which attributes each category should have. +--------+-----------+-----------------------------+ | cat_id | cat_name | attributes | +--------+-----------+-----------------------------+ | 1 |Membership | ["Type", "Duration"] | | 2 |Book | ["Title", "Author"] | | 3 |T-shirt | ["Size", "Colour", "Style"] | +--------+-----------+-----------------------------+ TEST DATA CREATE TABLE `product_j` ( `product_id` int(11) NOT NULL AUTO_INCREMENT, `prod_name` varchar(45) DEFAULT NULL, `category_id` int(11) DEFAULT NULL, `attributes` json DEFAULT NULL, PRIMARY KEY (`product_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; INSERT INTO `product_j` VALUES (1,'Standard Membership (12 months)',1,'{\"Type\": \"S\", \"Duration\": 12}'),(2,'Premium Membership (3 months)',1,'{\"Type\": \"P\", \"Duration\": 3}'),(3,'Brave New World',2,'{\"Title\": \"Brave New World\", \"Author\": \"Aldus Huxley\"}'),(4,'Philosophers Stone',2,'{\"Title\": \"Harry Potter and the Philosophers Stone\", \"Author\": \"JK Rowling\"}'),(5,'T-Shirt 1',3,'{\"Size\": \"M\", \"Color\": \"Red\", \"Style\": \"V-neck\"}'),(6,'T-Shirt 2',3,'{\"Size\": \"L\", \"Color\": \"White\", \"Style\": \"V-neck\"}'),(7,'T-Shirt 3',3,'{\"Size\": \"L\", \"Color\": \"Red\", \"Style\": \"V-neck\"}'),(8,'T-Shirt 4',3,'{\"Size\": \"L\", \"Color\": \"Black\", \"Style\": \"crew-neck\"}'),(9,'Goblet of Fire',2,'{\"Title\": \"Harry Potter and the Goblet of Fire\", \"Author\": \"JK Rowling\"}'); +------------+---------------------------------+-------------+------------------------------------------------------------------------------+ | product_id | prod_name | category_id | attributes | +------------+---------------------------------+-------------+------------------------------------------------------------------------------+ | 1 | Standard Membership (12 months) | 1 | {"Type": "S", "Duration": 12} | | 2 | Premium Membership (3 months) | 1 | {"Type": "P", "Duration": 3} | | 3 | Brave New World | 2 | {"Title": "Brave New World", "Author": "Aldus Huxley"} | | 4 | Philosophers Stone | 2 | {"Title": "Harry Potter and the Philosophers Stone", "Author": "JK Rowling"} | | 5 | T-Shirt 1 | 3 | {"Size": "M", "Color": "Red", "Style": "V-neck"} | | 6 | T-Shirt 2 | 3 | {"Size": "L", "Color": "White", "Style": "V-neck"} | | 7 | T-Shirt 3 | 3 | {"Size": "L", "Color": "Red", "Style": "V-neck"} | | 8 | T-Shirt 4 | 3 | {"Size": "L", "Color": "Black", "Style": "crew-neck"} | | 9 | Goblet of Fire | 2 | {"Title": "Harry Potter and the Goblet of Fire", "Author": "JK Rowling"} | +------------+---------------------------------+-------------+------------------------------------------------------------------------------+ CREATE TABLE `json_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `jdata` json DEFAULT NULL, `role` json DEFAULT NULL, `name` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; INSERT INTO `json_test` VALUES (1,'{\"town\": \"Chester\", \"county\": \"Cheshire\", \"country\": 1}','[1, 2, 3]','Peter'),(2,'{\"town\": \"Tenby\", \"county\": \"Pembrokeshire\", \"country\": 3}','[1, 3]','Paul'),(3,'{\"town\": \"Lancaster\", \"county\": \"Lancashire\", \"country\": 1}','[1, 2, 4]','Mary'),(4,'{\"town\": \"Dorchester\", \"county\": \"Dorset\", \"country\": 1}','[2, 4]','Jane'),(5,'{\"town\": \"Caernarfon\", \"county\": \"Cardigan\", \"country\": 3}','[1, 2, 3, 4]','Fred'); +----+-------------------------------------------------------------+--------------+-------+ | id | jdata | role | name | +----+-------------------------------------------------------------+--------------+-------+ | 1 | {"town": "Chester", "county": "Cheshire", "country": 1} | [1, 2, 3] | Peter | | 2 | {"town": "Tenby", "county": "Pembrokeshire", "country": 3} | [1, 3] | Paul | | 3 | {"town": "Lancaster", "county": "Lancashire", "country": 1} | [1, 2, 4] | Mary | | 4 | {"town": "Dorchester", "county": "Dorset", "country": 1} | [2, 4] | Jane | | 5 | {"town": "Caernarfon", "county": "Cardigan", "country": 3} | [1, 2, 3, 4] | Fred | +----+-------------------------------------------------------------+--------------+-------+ There's also a conventional country table +------------+--------------+ | country_id | country_name | +------------+--------------+ | 1 | England | | 2 | Scotland | | 3 | Wales | | 4 | Ireland | | 5 | France | | 6 | Italy | +------------+--------------+ TEST SQL QUERIES Alternative versions of same query (JSON_UNQUOTE vs double-arrow). Join on json array element. SELECT JSON_UNQUOTE(jdata->'$.town') as Town , JSON_UNQUOTE(jdata->'$.county') as County , country_name as Country FROM json_test j JOIN country c ON c.country_id = j.jdata->'$.country' ORDER BY jdata->'$.country'; SELECT jdata->>'$.town' as Town , jdata->>'$.county' as County , country_name as Country FROM json_test j JOIN country c ON c.country_id = j.jdata->'$.country' ORDER BY jdata->'$.country'; Search on json data SELECT product_id , attributes->>'$.Color' as color , attributes->>'$.Style' as size FROM products.product_j WHERE attributes->>'$.Size' = 'L' AND category_id = 3; Update json data UPDATE product_j SET attributes = JSON_SET(attributes, "$.Style", "Turtleneck") WHERE product_id = 8; I hope this gives a flavour of using json data. I wouldn't recommend using it all the time, as it breaks normalization rules, but it has its uses.
    1 point
  13. How about this? It's the table button next to the bullet and numbered list buttons.
    1 point
  14. An easier approach is to search for those records with today's char in the recurrence column set to "1" $sql = "SELECT id , recurrence , description , begindate , enddate FROM schedule WHERE ? BETWEEN begindate AND enddate AND SUBSTRING(recurrence, WEEKDAY(?)+1, 1) AND active "; $res = $pdo->prepare($sql); $searchDate = '2024-02-28'; $res->execute([$searchDate, $searchDate]); Example outputs searchdate = Feb 26 2024 (Monday) +----+------------+-------------+------------+------------+ | id | recurrence | description | begindate | enddate | +----+------------+-------------+------------+------------+ | 39 | 1010100 | Event1 | 2023-08-31 | 3000-01-01 | +----+------------+-------------+------------+------------+ searchdate = Feb 28 2024 (Wednesday) +----+------------+-------------+------------+------------+ | id | recurrence | description | begindate | enddate | +----+------------+-------------+------------+------------+ | 39 | 1010100 | Event1 | 2023-08-31 | 3000-01-01 | | 51 | 0010000 | Event2 | 2023-08-31 | 3000-01-01 | +----+------------+-------------+------------+------------+
    1 point
  15. lol. all the javascript posted for this problem is unnecessary. upon the DOM being loaded/rendered, it's getting data that's known at the time of the request for the map2.php page (the value being sent to getBookedSeats.php is coming from a js variable that's being set to a php value echoed on the page.) this is just a roundabout wall of code and data churn. here's a list of why this is not working - 1. you are making a POST request to getBookedSeats.php. the value won't be in any $_GET variable and adding an isset() won't make it work. all that did is hide the problem and caused the php code to be skipped over. 2. you are sending JSON encoded data to getBookedSeats.php. you would need to use the following to read and decode the data - $json = file_get_contents('php://input'); $data = json_decode($json,true); 3. the value will then be in $data['screeningId'], because that's the name of the javascript variable holding the value that you are sending in the ajax fetch request, which is a value that is coming from php in the first place.
    1 point
  16. Yes. That is what I was going to suggest if you didn't want to use the hidden field approach. That way you send just a single querystring which will be handled automatically to create the $_POST array Perhaps $stmt = $pdo->prepare("INSERT INTO mytable (zoneType, zoneName, printValue) VALUES (?,?,?)"); foreach ($_POST['zoneName'] as $k => $zn) { if ($zn) { $stmt->execute([ $_POST['zoneType'][$k], $zn, $_POST['printValue'][$k] ]); } }
    1 point
  17. Only when you need to report an error that the user can do something about (like duplicates). Most DB errors are beyond user control so I don't bother with try..catch and just let php handle the error
    1 point
  18. Aside from the empty WHERE clause mentioned by @gizmola above, you may also have a problem with passing your limit and offset parameters. You don't show us the relevant connection and execution code, but If your PDO connection code does not set ATTR_EMULATE_PREPARES to false (the default is true) then you cannot pass the limit and offset as parameters in an array when executing. You can, however, pass them using bindParam() You should always set this attribute to false
    1 point
This leaderboard is set to New York/GMT-04: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.