Jump to content

Barand

Moderators
  • Posts

    24,608
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. @ginerjm is correct. You cannot pass table or column names as parameters to a prepared query; only data values. It sounds like you need to do something like this (three table example for brevity) DELETE table1, table2, table3 FROM table1 JOIN table2 USING (job_id) JOIN table3 USING (job_id) WHERE table1.job_id = ?
  2. Something along these lines... include("path/to/simple_html_dom.php"); $html = file_get_html('mysource.html'); $rows = $html->find('tr[bgcolor="#EEEEEE"]'); $stmt = $conn->prepare("INSERT INTO thetable (uid, ... , etc)" VALUES(?,?,?, ...., etc)); foreach ($rows as $row) { if (strpos($row->children(0), '<th>')!==false) continue; $data = []; foreach ($row->children() as $k => $itm) { $val = $itm->plaintext; switch ($k) { case 6: // DoB case 9: // Expires $data[] = reformatDate($val); break; case 7: // Height case 8: // Weight case 10: // Wage $data[] = numOnly($val); break; case 11: // Value $data[] = reformatValue($val); break; default: $data[] = $val; } } $stmt->execute($data); } function reformatDate($str) { list($dob) = explode(' ', $str); $res = (DateTime::createFromFormat('d/m/Y', $dob))->format('Y-m-d') ; return $res; } function numOnly($str) { $res = ''; for($i=0, $k=strlen($str); $i<$k; $i++) { $res .= ctype_digit($str[$i]) ? $str[$i] : ''; } return $res; } function reformatValue($str) { // // This is left as an exercise for the reader! // return $str; // leave unchanged for now }
  3. Example pagination code here
  4. You would do the required formatting before writing to the csv file. LOAD DATA INFILE command has a "IGNORE N rows" option for ignoring headings. If you don't want to use that LOAD DATA option (which is certainly the fastest and will load hundreds of records per second) then , with a PDO connection and a prepared statement you could change the loop to $stmt = $conn->prepare("INSERT INTO thetable (uid, ... , etc)" VALUES(?,?,?, ...., etc)); foreach ($rows as $row) { $data = []; foreach ($row->children() as $itm) { $val = $itm->plaintext; // do any required reformatting here $data[] = $val; } $stmt->execute($data); }
  5. Mainly, but it also saves having to escape string data too (For example, if you were trying to add "O'Reilly" as a name value.
  6. 1. Your code needs to open with <?php 2. Your timezone is invalid, use date_default_timezone_set("Europe/Oslo"); 3. If you exit before the redirect, how can it redirect? 4. The concatenation operator in php is "." and not "+" I recommend you turn error reporting on.
  7. A time stamp (eg 2019-12-15 19:02:00) is a string value and should therefore be inside single quotes in your query. (This would be the same in C# as it is purely SQL related, not C# or PHP). You should (in either language) be using prepared queries and not embedding variables in the query. For example (using PDO) $stmt = $conn->prepare("UPDATE userData SET timestamp = ? WHERE GUID = ?") $stmt->execute([ $timeStamp, $LoggedIn_guid ]);
  8. P.S. Some of the data is unsuitable for data storage purposes and needs to be reformatted before storing in a database table +------------+--------------------------------+----------------+----------------------------------+ | Column | WRONG | CORRECT | Comments | +------------+--------------------------------+----------------+----------------------------------+ | Age | 31 | Not required | DoB tells you the age | | DoB | 3/4/1988 (31 years old) | 1988-04-03 | Store in correct date format | | Height | 194 cm | 194 | Store unformatted numeric value | | Weight | 83 kg | 83 | Store unformatted numeric value | | Expires | 30/6/2022 | 2022-06-30 | Store in correct date format | | Wage | £25,000 p/w | 25000 | Store unformatted numeric value | | Value | £12.75M | 12750000 | Store unformatted numeric value | +------------+--------------------------------+----------------+----------------------------------+
  9. Try using domDocument or simple_html_dom. EG include("/path/to/simple_html_dom.php"); $html = file_get_html('my_source.html'); $rows = $html->find('tr[bgcolor="#EEEEEE"]'); $csvFile = fopen('mydata.csv', 'w'); foreach ($rows as $row) { $data = []; foreach ($row->children() as $itm) { $data[] = $itm->plaintext; } fputcsv($csvFile, $data); } fclose($csvFile); The csv file can then be loaded into a sql table using a LOAD DATA INFILE statement.
  10. You have taken the "|" characters out! How do expect to split it? The echoed string should look like guid|username|health|...|misses I.E. $row = [ 'guid' => 'xyz', 'username' => 'fred', 'health' => 1, 'level' => 42 ]; echo $row['guid'] . '|' . $row['username'] . '|' . $row['health'] . '|' . $row['level']; or (easier if you want every $row item in their natural ORDER) echo join('|', $row); Then when you split it, the array will look like Array ( [0] => xyz [1] => fred [2] => 1 [3] => 42 )
  11. If you are splitting on "|", why put the PHP_EOLs in there? Also, try omitting the leading "|" in your string, so you have guid|username|health|...|misses When you split that on "|" the guid should be item 0. With the leading "|" (i.e "| guid | username | …") I would expect item 0 to be blank after the split and guid would be item 1..
  12. As you can see from @Psycho's comments, that was your first mistake.
  13. Put this line mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); before your mysqli connection line. Errors will then be reported automatically.
  14. Then use basename()
  15. So does it now work OK?
  16. You have a database named "*" !?
  17. Put this line of code immediately before your line containing mysqli_connect mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); That should get itt to report automatically any mysqli errors (such as the prepare() failing.
  18. I'm afraid that my answer is "Not a lot". Grouping by appointment_id will give you one row in the result set for each appointment. The contents of fields other than the appointment_id will be arbitrary. Don't use "select * ", define the columns you need. That query doesn't require preparing (no user data values) and executing. You could just use $dbh->query($q).
  19. A good source for php/MySQL interaction (using PDO is recommended) is https://phpdelusions.net/pdo_examples This query should get you started SELECT , scheduled_student_service , category , COUNT(*) as total_appointments , SUM(is_no_show) as no_shows , SUM(is_cancelled) as cancellations FROM thetable GROUP BY scheduled_student_service, category If that isn't what you want, repost with more details. In future, please don't post images of data. They are as much use as chocolate teapots if we need to recreate your data to test with when helping.
  20. Your form should contain a hidden field for the clientID then three selects for each engineer, indexed by the engineers' ids hidden name=clientID value=$clientID For each engineer: select name=job[$engID] select name=company[$engID] select name=site[$engID] To process the POST data foreach ($_POST['job' as $engID => $job) { $company = $_POST['company''][$engID']; $site = $_POST['site'][$engID]; // update database with the engineer, job, company, site values }
  21. The first record should always be the best match so you could add "LIMIT 1' to the end of the query and just process the single result. Check the values in the record and take the appropriate action. However, I don't now how your process operates so I don't know how significant other records in the results are if the first does not adequately suit the order.
  22. Perhaps something without all those non-breaking spaces <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Lang" content="en"> <title>Example</title> <style type="text/css"> table { width: 80%; margin: 20px auto; font-family: calibri, sans-serif;} caption { border-bottom: 1px solid gray; } th { text-align: left; padding: 8px 2px; color: #999;} td { color: #25b0e9; padding: 8px 4px; } </style> </head> <body> <table> <caption>Channel State</caption> <tr> <th>&nbsp;</th> <th>C1</th> <th>C2</th> <th>C3</th> <th>C4</th> <th>C5</th> <th>C6</th> <th>C7</th> <th>C8</th> </tr> <tr> <th>Left (+)</th> <td>&check;</td> <td>&check;</td> <td>&check;</td> <td>&nbsp;</td> <td>&check;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <th>Left (-)</th> <td>&nbsp;</td> <td>&nbsp;</td> <td>&check;</td> <td>&check;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </body> </html>
  23. As you test data contained only a menu that was a perfect match to the test order and a menu that contained everything I added a couple of extra menus and orders. SELECT m.menu_id , m.menu_name , COUNT(*) as matched , ROUND(count(*)/menuitems*100, 1) as `%menu` , ROUND(count(*)/orderitems*100, 1) as `%order` FROM ssm_menu m INNER JOIN ssm_menu_connection c ON c.menu_id = m.menu_id INNER JOIN ssm_menu_order o ON o.menu_item_id = c.menu_item_id INNER JOIN ( SELECT job_id , COUNT(DISTINCT menu_item_id) as orderitems FROM ssm_menu_order GROUP BY job_id ) jtot ON jtot.job_id = o.job_id INNER JOIN ( SELECT menu_id , COUNT(DISTINCT menu_item_id) as menuitems FROM ssm_menu_connection GROUP BY menu_id ) mtot ON m.menu_id = mtot.menu_id WHERE o.job_id = 27 GROUP BY m.menu_id ORDER BY matched DESC, `%menu` DESC, `%order` DESC; +---------+----------------------------------------------------------+---------+-------+--------+ | menu_id | menu_name | matched | %menu | %order | +---------+----------------------------------------------------------+---------+-------+--------+ | 1 | Menu One | 3 | 100.0 | 100.0 | | 2 | Private Dinner Party/Wedding - 3 Course Fine Dining Menu | 3 | 18.8 | 100.0 | | 3 | Menu Three | 2 | 66.7 | 66.7 | | 4 | Menu Four | 2 | 50.0 | 66.7 | | 5 | Menu Five | 1 | 25.0 | 33.3 | +---------+----------------------------------------------------------+---------+-------+--------+
  24. OK. I'm going to be in head-scratching mode for a while (enlarging my bald patch). I'll get back when I have something.
  25. Am I right in thinking that, as well as the % of the menu used by the order, you would want the % of the order covered by the menu?
×
×
  • 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.