Jump to content

Barand

Moderators
  • Posts

    24,605
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. That line is setting the session value to an array. did you mean = $_POST['username'] ?
  2. 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 }
  3. 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?
  4. 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':''; }
  5. 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>
  6. 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.
  7. 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.
  8. w3-disabledDiskuter ^^^^^^^^^^^ Blatantly obvious that it should be with the other w3-xxxxx classes.
  9. <a id="nav-panel" href="<?=$HOST?>panel.php" class="w3-bar-item w3-button <?=$disabl?>">Diskuter</a>
  10. $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 ] );
  11. 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.
  12. 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.
  13. 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
  14. 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 | +---------+------+------+------+------+------+------+
  15. Use a table subquery to calculate the maximum version for each user, then count those by country/varsion.
  16. 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>
  17. 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.
  18. I am not sure just how a cron job can be secured. Any security features may need to be within the functions themselves or the data.
  19. Seems like you want eight cron jobs (four for each job) that run on the same date every year.
  20. Get a decent editor! Four errors found... Unwanted single quote Mispelled and unwanted "</label>" Mispelled and unwanted "</label>" Missing "a" at start of "<a .... "
  21. This example will repopulate the category menu depending on the selected type <html> <head> <title>Sample</title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> // array of categories for each type var cat_types = JSON.parse('{"A":{"1":"Cat 1","2":"Cat 2","3":"Cat 3"},"B":{"4":"Cat 4","5":"Cat 5","6":"Cat 6"},"C":{"7":"Cat 7","8":"Cat 8","9":"Cat 9"}}'); $().ready(function() { // populate type menu $.each(cat_types, function(k,v) { $("#type").append($("<option>", {"val":k, "text":k})) }) // when type selected, populate cat menu $("#type").change( function() { $("#cat").html("<option value=''> - select category -</option"); var type = $(this).val() $.each(cat_types[type], function(k, v) { $("#cat").append($("<option>", {"val":k, "text":v})) }) }) }) </script> <style type='text/css'> </style> </head> <body> <form> Type <select name='type' id='type'> <option value=""> - select type -</option> </select> <br><br> Cat <select name='cat' id='cat'></select><br> </form> </body> </html>
  22. To do pagination successfully you need to know the total number of pages. That means a query at the start to count the number of rows. You are correct in using SELECT COUNT(*), however using mysql_num_rows after that query will always return "1" as the query will return a single row containing the count. All you need to do is read the count column value returned. $res = $conn->query("SELECT COUNT(*) FROM table1"); // get the count $total_recs = $res->fetch_row()[0]; // read the first column of the returned row You would use the query with LIMIT clause once you know which page to get.
  23. Or avoid the concatenation which is usually the biggest source of error (and the query string needs an "=") echo "<a href='icerik.php?icerik={$goster['icerik_id']}'>{$goster['baslik']}</a>";
  24. @ginerjm has just told you what's wrong.
×
×
  • 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.