Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. That line in your onchange function concerns me. If it was generated when PHP was executing. how does it relate to the id of the product the user is clicking in the browser?
  2. Because there is a mix of old (edited) records and new ones, the simplest way to update the DB is with INSERT INTO tablename (id, list_order, food, price) VALUES ( ?, ?, ?, ?) ON DUPLICATE KEY UPDATE list_order = VALUES(list_order), food = VALUES(food), price = VALUES(price); I too normally like the food[x][field] naming method, but this insert/update method would require that all the new ones all had zero id. As array keys can't be duplicated then using the id in the field naming becomes a problem. I would also use a hidden id field but go with List order <input type="text" name="list_order[]" value="<?= $result['list_order']?>"><br> Food item <input type="text" name="food[]" value="<?= $result['food']?>"><br> Price (each) <input type="text" name="price[]" value="<?= $result['price']?>"> <input type="hidden" name="id[]" value="<?= $result['id']?>"> using 0 instead of $result['id'] for the id values in the new ones
  3. But have you tried the method I flowcharted for you?
  4. Think of radio buttons as menu options. They need the same name (so the browser knows they are part of the same menu) but different values that the user selects. Use the id (image id I presume) as part of the name to group them <input type="radio" name="action[<?=$result['id']?>]" value="A"> Approve <input type="radio" name="action[<?=$result['id']?>]" value="D"> Delete Then to process the form data foreach ($_POST['action'] as $id => $action) { if ($action == 'D') { // delete image whose ID is $id } elseif ($action == 'A') { // approve image whose ID is $id } }
  5. Firstly, I doubt anyone is clicking a link from a first-time poster. Second, what you are doing, updating with parts of a column, is indicative of problems in the database design. What is the structure of those two tables and what does the data look like in the relevant columns?
  6. <?php header("Location: Startseite.php"); ?>
  7. OK. Back to your original file format. I showed you the logic to use in your code. Have you even attempted that method yet? (it's only about six or seven lines of code) If you at least try, you get more help. Or are you just upset because no one wrote the actual code for you
  8. When I last worked with LDAP, I just used to interrogate the network LDAP servers to see who was logged in and what groups/depts etc they were in. ($_SERVER['login_user'])
  9. That line is setting the session value to an array. did you mean = $_POST['username'] ?
  10. If no login data has yet been sent to the form, there will be no POST data (such as when the page first loads). You need to check if data was posted if ($_SERVER['REQUEST_METHOD']=='POST') { // your above code goes here }
  11. My last post (3 hrs ago) sets is_active to true/false depending on the opening times and current day/time. Problem solved isn't it?
  12. Assuming day #1 is Monday, $xml = simplexml_load_string($str); foreach ($xml->xpath("//offer") as $offer) { $open = json_decode((string)$offer->opening_times,1); $today = new DateTime('now', new DateTimeZone($open['timezone'])); $now = $today->format('H:i'); $day = $today->format('N'); $offer->is_active = ($open[$day][0]['opening'] <= $now && $now <= $open[$day][0]['closing']) ? 'true':''; }
  13. try $xml = simplexml_load_string($str); foreach ($xml->xpath("//offer") as $o) { $o->is_active = 'true'; } gives <?xml version="1.0" encoding="UTF-8"?> <offers> <offer> <id><![CDATA[2109]]></id> <name><![CDATA[Sleek Frozen Sausages]]></name> <category><![CDATA[Sleek]]></category> <description><![CDATA[Eum aut qui est delectus suscipit aut voluptas quaerat maiores architecto perferendis dolorum tenetur iure nemo omnis laboriosam voluptatem et iste molestias sed voluptas eum facilis aliquam tempora autem aspernatur ipsum corrupti cum corrupti quae dolor modi consequatur provident illo maiores eius aspernatur id nostrum nisi repellat enim a hic unde laboriosam possimus est ipsam qui mollitia nesciunt est culpa voluptatem sit dignissimos quidem facilis dolorem facilis et explicabo ea veniam quis architecto autem occaecati quaerat omnis reprehenderit doloribus labore saepe asperiores a ea possimus dolor necessitatibus numquam doloremque velit fuga ipsam numquam quia omnis voluptas voluptas rerum sint eveniet sit in error quia nemo delectus perferendis asperiores quam quam assumenda reiciendis sunt aut et saepe ea adipisci eum debitis odit similique consectetur nesciunt ducimus maxime sed consequuntur repellendus qui illum vero necessitatibus perferendis cumque optio voluptatibus et quas velit voluptatem tempore est et officiis tempora iusto rerum eum amet a qui corrupti ex nobis laborum eum assumenda velit laboriosam et sed sapiente accusantium officia enim doloremque perspiciatis quos ut rerum molestias ut ut aut omnis vitae placeat voluptas iusto distinctio ea molestias et at et aliquam libero non neque dicta quos numquam est non explicabo ipsa neque dolores rerum.]]></description> <price><![CDATA[252.65 EUR]]></price> <url><![CDATA[https://example.com/product/2109]]></url> <image_url><![CDATA[http://lorempixel.com/640/480]]></image_url> <opening_times><![CDATA[{"1":[{"opening":"10:00","closing":"22:30"}],"2":[{"opening":"10:00","closing":"22:30"}],"3":[{"opening":"10:00","closing":"22:30"}],"4":[{"opening":"10:00","closing":"22:30"}],"5":[{"opening":"10:00","closing":"22:30"}],"6":[{"opening":"10:00","closing":"22:30"}],"7":[],"timezone":"Europe/Warsaw"}]]></opening_times> <is_active>true</is_active> </offer> <offer> <id><![CDATA[7673]]></id> <name><![CDATA[Ergonomic Soft Fish]]></name> <category><![CDATA[Rustic]]></category> <description><![CDATA[Pariatur consectetur autem reiciendis ab ea est fugiat tenetur suscipit ut sit rem accusamus accusamus accusamus veniam commodi omnis quia minus ratione reprehenderit est porro omnis modi et ipsa aut itaque impedit inventore modi nisi nemo commodi nesciunt earum quia sed assumenda nulla quia qui neque laborum vitae nobis dolorem perspiciatis tenetur nisi asperiores eos itaque dolorem sit est nostrum sequi similique doloremque vero id voluptas exercitationem eveniet saepe non impedit aut neque aut sed molestiae aut cum hic consectetur facilis porro atque perspiciatis maiores maiores ut aut enim iste maxime dolores est dolores quaerat dolores error nisi et esse voluptas occaecati nostrum quasi vero porro natus iste molestiae totam culpa vero voluptate porro aut ut iusto non ullam quam aut itaque velit quis maiores nobis officia ut iure voluptatibus iure nihil optio repellendus eum similique eum in excepturi doloremque rerum cumque accusantium fuga sed sed odit vel qui nam eum iure sapiente magni et temporibus quis qui pariatur tempora odit explicabo et mollitia autem nihil autem repellat ut et laudantium ab dolores nisi porro fuga sed laudantium quae delectus debitis quaerat doloremque praesentium quod ullam accusamus architecto earum impedit esse sint sint fugiat nihil itaque ut ut aut provident.]]></description> <price><![CDATA[384.12 EUR]]></price> <url><![CDATA[https://example.com/product/7673]]></url> <image_url><![CDATA[http://lorempixel.com/640/480]]></image_url> <opening_times><![CDATA[{"1":[{"opening":"14:00","closing":"23:00"}],"2":[{"opening":"14:00","closing":"23:00"}],"3":[{"opening":"14:00","closing":"23:00"}],"4":[{"opening":"14:00","closing":"23:00"}],"5":[{"opening":"14:00","closing":"23:00"}],"6":[{"opening":"14:00","closing":"23:00"}],"7":[],"timezone":"Europe/Warsaw"}]]></opening_times> <is_active>true</is_active> </offer> </offers>
  14. The easiest way is to spray your code liberally with a DataKillTM aerosol. This is known to eliminate 99.99% of all program bugs. If you can't get hold of a can, you'll have to manually debug your code.
  15. Having the item name POSTed to your page can also be a nightmare. Users are not renowned for consistency. So many possible variations HP OfficeJet Pro:9015e OfficeJet Pro 9015e HP Pro:9015e HP Officejet 9015E HP Pro 9015 e HP 9015e HP9015e Better by far if you can get a product ID.
  16. w3-disabledDiskuter ^^^^^^^^^^^ Blatantly obvious that it should be with the other w3-xxxxx classes.
  17. <a id="nav-panel" href="<?=$HOST?>panel.php" class="w3-bar-item w3-button <?=$disabl?>">Diskuter</a>
  18. $item still requires the quotes around it, just like HIN did. PS Instead of putting variables in the query, you should use prepared queries with placeholders for the values $item = "HIN"; $stmt = $pdo->prepare("SELECT * FROM book WHERE solution=? ORDER BY id"); $stmt->execute( [ $item ] );
  19. It's the antithesis of progress and learning. We can only tell him stuff that he already knows, which is pointless. If he doesn't know it he won't use it. Therefore, whatever we tell him is a waste of time.
  20. Your code is wrong for several reasons, but I won't go into them as trying to help you is apparently a complete waste of time. Goodbye.
  21. The subquery calculating the maximum scores .behaves just like a temporary table. So you can the join it to table1 using user and count by country. SELECT a.country , sum(b.version=1) as V1 , sum(b.version=2) as V2 , sum(b.version=3) as V3 , sum(b.version=4) as V4 , sum(b.version=5) as V5 , sum(b.version=6) as V6 FROM table1 a JOIN ( SELECT user , MAX(version) as version FROM table2 GROUP BY user ) b USING (user) GROUP BY country ORDER BY country DESC; +---------+------+------+------+------+------+------+ | country | V1 | V2 | V3 | V4 | V5 | V6 | +---------+------+------+------+------+------+------+ | USA | 0 | 0 | 0 | 0 | 0 | 1 | | France | 0 | 0 | 2 | 0 | 0 | 0 | +---------+------+------+------+------+------+------+ I know
  22. The subquery calcultaing the maximum scores .behaves just like a temporary table. So you can the join it to tbale using user and count by country. SELECT a.country , sum(b.version=1) as V1 , sum(b.version=2) as V2 , sum(b.version=3) as V3 , sum(b.version=4) as V4 , sum(b.version=5) as V5 , sum(b.version=6) as V6 FROM table1 a JOIN ( SELECT user , MAX(version) as version FROM table2 GROUP BY user ) b USING (user) GROUP BY country ORDER BY country DESC; +---------+------+------+------+------+------+------+ | country | V1 | V2 | V3 | V4 | V5 | V6 | +---------+------+------+------+------+------+------+ | USA | 0 | 0 | 0 | 0 | 0 | 1 | | France | 0 | 0 | 2 | 0 | 0 | 0 | +---------+------+------+------+------+------+------+
  23. Use a table subquery to calculate the maximum version for each user, then count those by country/varsion.
  24. Using a DB, I'd do it this way (tables used are from my SQL tutorial). Select a house name and the pupils menu lists pupils from that house. <?php const HOST = 'localhost'; const USERNAME = '????'; const PASSWORD = '????'; const DATABASE = 'jointute'; // default db $db = pdoConnect(); //============================================================================== // HANDLE AJAX CALLS // if (isset($_GET['ajax'])) { if ($_GET['ajax']=='pupilopts') { exit( json_encode(pupilOptions($db, $_GET['hid']))); } exit('INVALID REQUEST'); } //============================================================================== function houseOptions($db) { $opts = "<option value=''>- select house -</option>\n"; $res = $db->query("SELECT houseID , house_name FROM house ORDER BY house_name "); foreach ($res as $r) { $opts .= "<option value='{$r['houseID']}'>{$r['house_name']}</option>\n"; } return $opts; } function pupilOptions($db, $hid) { $opts = []; $res = $db->prepare("SELECT pupilID , CONCAT(lname, ', ', fname) as name FROM pupil WHERE houseID = ? ORDER BY lname, fname "); $res->execute([$hid]); $pups = $res->fetchAll(); $opts = array_column($pups, 'name', 'pupilID'); sort($opts); return $opts; } function pdoConnect($dbname=DATABASE) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } ?> <!DOCTYPE html> <html lang='en'> <head> <title>Example</title> <meta charset='utf-8'> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#houses").change( function() { var hid = $(this).val() $.get( "", // specify processing file on server (in this case it's same file) {"ajax":"pupilopts", "hid":hid}, // data to send in request function(resp) { // handle the response $("#pupils").html("<option value=''> - select pupil -</option"); $.each(resp, function(k, v) { $("#pupils").append($("<option>", {"val":k, "text":v})) }) }, "JSON" // response type ) }) }) </script> <style type='text/css'> body { font-family: calibri, sans-serif; font-size: 12pt; } div { margin: 16px; padding: 8px; border: 1px solid gray; } label { display: inline-block; background-color: black; color: white; width: 120px; padding: 8px; margin: 1px 8px; } </style> </head> <body> <div> <label>House</label> <select id="houses" > <?= houseOptions($db) ?> </select> </div> <div> <label>Pupil</label> <select id="pupils" > <!-- pupil options --> </select> </div> </body> </html>
  25. It's one way, and if I didn't have a database, it's as good a way as any. If I did have a DB I'd do it differently. But given no information to the contrary, I did it that way. A DB solution would use elements of that code, such as building the category 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.