Jump to content

Barand

Moderators
  • Posts

    24,612
  • Joined

  • Last visited

  • Days Won

    834

Everything posted by Barand

  1. 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.
  2. 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>
  3. 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 | +---------+----------------------------------------------------------+---------+-------+--------+
  4. 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.
  5. 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?
  6. Thanks, that loaded OK. I'll look at your problem, which I interpret as ranking the menus by percentage of content of the ordered items. I expect there could be a situation where items A,B,C,D,E are ordered menu 1 contains A,B,C. menu 2 contains B,C,D menu 3 contains C,D,E ie No single menu contains all items ordered?
  7. Tell me how to load those images into a test database and I'll continue to help.
  8. Can you provide some actual data that might give us more of an insight into what you want - a dump of those tables perhaps?
  9. The question has been answered as detailed as we can from the information provided.
  10. Here's a simplified example $uid = 2; $res = $bdd->prepare("SELECT f.id , f.name , u.file_id FROM files f LEFT JOIN user_files u ON f.id = u.file_id AND u.user_id = ? ORDER BY f.id "); $res->execute([$uid]); $tdata = ''; foreach ($res as $row) { $disabled = $row['file_id'] ? 'disabled' : ''; $tdata .= "<tr> <td>{$row['id']}</td> <td>{$row['name']}</td> <td><button $disabled>Download</button></td> </tr> "; } ?> <html> <head> <title>Example</title> </head> <body> <table> <?=$tdata?> </table> </body> </html>
  11. Have you tried recreating test files in your database using images as input? SHOW CREATE TABLE files; SHOW CREATE TABLE user_files; Use a single query on both tables and use a LEFT JOIN. That way you know which are present in both tables. Disable the button where the file is in both.
  12. Only select check boxes (and radio buttons) are sent in the form data so you need you check if they are present using isset(). Example <?php for ($i=1; $i<=5; $i++) { if (isset($_GET['mycb'][$i])) { echo "Check box $i selected<br>" ; } } ?> <html> <head> <title>Example</title> </head> <body> <hr> <form> Check box 1 : <input type="checkbox" name="mycb[1]" value="1"><br> Check box 2 : <input type="checkbox" name="mycb[2]" value="2"><br> Check box 3 : <input type="checkbox" name="mycb[3]" value="3"><br> Check box 4 : <input type="checkbox" name="mycb[4]" value="4"><br> Check box 5 : <input type="checkbox" name="mycb[5]" value="5"><br><br> <input type="submit" name="btnSub" value="Submit"> </form> </body> </html>
  13. What is the query to get $row? What is the query to get $row2? (If you used "SELECT * ' the provide the table structures too)
  14. If it toggles every hour then the time-based value does not require a cron job. The value is available anytime you need it SELECT HOUR(NOW()) MOD 2 as value
  15. UPDATE tableZ SET x = (x = 0) WHERE id = 1
  16. A couple of methods spring to mind 1 ) toggle the value between 0 and 1 ... UPDATE tableZ SET x = CASE WHEN x = 1 THEN 0 ELSE 1 END; or UPDATE tableZ SET x = (x = 0); 2 ) set it based on the time UPDATE tableZ SET x = HOUR(NOW()) MOD 2; Of course the queries may need a WHERE clause unless you want to apply the change to every record in tableZ.
  17. As @mac_gyver said, when the user registers, create a hash of their password using password_hash() and store that hash value, not the plain-text value. You then verify the password hash using password_verify() (See line 36 in the code) That being said, my test table for the code below is ... CREATE TABLE `sam_user` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `eml` varchar(50) DEFAULT NULL, `pass` varchar(120) DEFAULT NULL, `type` varchar(10) NOT NULL DEFAULT 'user', PRIMARY KEY (`user_id`), UNIQUE KEY `idx_sam_user_eml` (`eml`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +---------+---------------+--------------------------------------------------------------+-------+ | user_id | eml | pass | type | +---------+---------------+--------------------------------------------------------------+-------+ | 1 | [email protected] | $2y$10$OKAmeyWZpKJcg/VgPAcx3uQr7R1KF23pPZFapmOmn0BhnWLqqVAP6 | user | | 2 | [email protected] | $2y$10$NeqCtTFo79wxGyAacPJLbeyU7Er4hPKrjwZv1G/Vr6YgHV/vnV9.6 | std | | 3 | [email protected] | $2y$10$6TBuStg179rLeMOm2URoNuwEOseYyOIXEVTvbwq7x9G5c9Jw0Bxoi | admin | +---------+---------------+--------------------------------------------------------------+-------+ This is my version of your code ... <?php session_start(); include 'db_inc.php'; // database credentials and custom pdoConnect function $db = pdoConnect('test'); // connect to DB 'test' using PDO // DEFAULT FORM VALUES $eml = ''; $pass = ''; $messages = ''; // HAS FORM DATA BEEN POSTED? if ($_SERVER['REQUEST_METHOD'] == 'POST') { $post = array_map('trim', $_POST); $eml = $post['eml'] ?? ''; $pass = $post['pass'] ?? ''; $errors = []; if ($post['eml']=='') { $errors[] = 'You must enter your email address'; } if ($post['pass']=='') { $errors[] = 'You must enter your password'; } $stmt = $db->prepare("SELECT user_id , pass , type FROM sam_user WHERE eml = ? "); $stmt->execute([$post['eml']]); $row = $stmt->fetch(); if (!$row) { $errors[] = "Invalid login request"; } else { if (!password_verify($post['pass'], $row['pass'])) { // verify the hashed password $errors[] = "Invalid login request"; } } if (!$errors) { $_SESSION['user'] = $row['user_id']; $qdata = []; switch ($row['type']) { case 'admin': $page = 'wel.php'; $qdata['msg'] = 'Administrator successfully logged in'; break; case 'std': $page = 'mod.php'; $qdata['msg'] = 'Moderator successfully logged in'; break; default: $page = 'sim.php'; $qdata['msg'] = 'User successfully logged in'; break; } $qstr = http_build_query($qdata); $url = "{$page}?{$qstr}"; // header("Location: $url"); // uncomment in production version echo $url; // TESTING ONLY exit; } else { unset($_SESSION['user']); $messages = "<div class='errors'>" . join('<br>', $errors) . "</div>\n"; } } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta charset="utf-8"> <title>Example Login</title> <style type="text/css" media="screen"> body { font-family: calibri, sans-serif; font-size: 12pt; } header { padding: 25px; text-align: center; background-color: #2DABE1; color: #FFF;} label { width: 100px; height: 40px; font-weight: 600; display: inline-block; } fieldset { width: 300px; margin: 100px auto; padding: 20px; } .errors { width: 300px; background-color: #E02222; color: #FFF; margin: 0 auto; padding: 20px;} </style> </head> <body> <header> <h1>Example Login</h1> </header> <form action="" method="post"> <fieldset> <label>Email</label><input type="text" name="eml" value='<?=$eml?>'><br> <label>Password</label><input type="password" name="pass" value='<?=$pass?>'><br> <label>&nbsp;</label><input type="submit" name="sb" value='Log In'> </fieldset> </form> <?=$messages?> </body> </html>
  18. Do you have a particular reason for posting that mess?
  19. It's a simple enough process Get exif data from the original image and print it Rotate the image Get the exif data from the rotated image and print it What in there is so difficult?
  20. I gave you the code to show the before and after exif data. How much of clue do you need?
  21. So our giving you yet another example would just be a waste of time, wouldn't it?
  22. Have you looked at the examples on the pages you've been linked to? How do they NOT help?
  23. elseif (is_numeric($minPrice)) probably needs to be elseif (!is_numeric($minPrice)) // error if NOT numeric
  24. Then it sounds like your rotation function is the same as you posted earlier - yes? $filename = '/images/myphoto.jpg'; $exif = exif_read_data($filesname); echo '<pre>BEFORE: ' . print_r($exif, 1) . '</pre>'; correctImageOrientation($filename); $exif = exif_read_data($filesname); echo '<pre>AFTER: ' . print_r($exif, 1) . '</pre>';
×
×
  • 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.