Jump to content

Barand

Moderators
  • Posts

    24,437
  • Joined

  • Last visited

  • Days Won

    808

Community Answers

  1. Barand's post in How to calculate price of 1 or more hotel rooms in php using arrays was marked as the answer   
    Alternatively
    $bookquery = array_filter($bookquery, fn($v)=>in_array($v['room_id'], $reservedrooms)); $totalprice = array_sum(array_column($bookquery, 'price'));  
  2. Barand's post in Select statement selecting wrong data was marked as the answer   
    Just using the single available table here...
    SELECT dr.id , device_id , status_id , action_time FROM deployment_register dr JOIN ( SELECT device_id , MAX(action_time) as action_time FROM deployment_register WHERE status_id IN (2, 5) GROUP BY device_id ) latest USING (device_id, action_time); +----+-----------+-----------+---------------------+ | id | device_id | status_id | action_time | +----+-----------+-----------+---------------------+ | 7 | 3 | 5 | 2023-10-07 21:06:45 | +----+-----------+-----------+---------------------+ Subquery to find latest row for each device then join against that.
  3. Barand's post in php count lines in a text file with a specific variable was marked as the answer   
    code
    $data = file('data.txt', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); usort($data, fn($a, $b)=>substr($a,11,2)<=>substr($b,11,2)); // sort by code number $codes = []; foreach ($data as $d) { $p = strpos($d, ')'); $k = substr($d, 11, $p-10); if (!isset($codes[$k])) { $codes[$k] = 1; } else { $codes[$k]++; } } echo (join("<br>", $data)); echo ("<h3>Total clicks</h3>"); foreach ($codes as $code => $total) { printf("%s Total clicks = %d<br>", $code, $total); } output
    15/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Finland Helsinki Uusimaa 18/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Finland Helsinki Uusimaa 21/09/2023 03 Resist the Curse (Resiste la Maldición) 11-12-2022.mp3 Germany Gera Thuringia 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Edmore Michigan 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Alhaurin de la Torre Malaga 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Alhaurin de la Torre Malaga 14/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Madrid Madrid 15/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United States Cedar Springs Michigan 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 Spain Nerja Malaga 16/09/2023 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) 10-9-2023.mp3 United Kingdom Sheffield Sheffield 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Cartagena Murcia 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Chesaning Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Edmore Michigan 21/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 Spain Nerja Malaga 22/09/2023 05 Day of Atonement 2023 (Día de la Expiación) 17-9-2023.mp3 United States Garden City New York 21/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 Norway Sira Agder 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United Kingdom Sheffield Sheffield 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 Spain Muro del Alcoy Alicante 08/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 09/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Edmore Michigan 10/09/2023 19 The Bread of Life (El Pan de la Vida) 27-8-2023.mp3 United States Cedar Springs Michigan 11/09/2023 20 The Legacy of Jesus (El Legado de Jesús)20-8-2023.mp3 United States Ashburn Virginia 15/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Finland Helsinki Uusimaa 18/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Finland Helsinki Uusimaa 21/09/2023 20 Be With Me Where I Am (Está Conmigo Donde Estoy)20-8-2017.mp3 Germany Gera Thuringia Total clicks 03 Resist the Curse (Resiste la Maldición) Total clicks = 3 04 Feast of Trumpets 2023 (Fiesta de las Trompetas) Total clicks = 19 05 Day of Atonement 2023 (Día de la Expiación) Total clicks = 12 19 The Bread of Life (El Pan de la Vida) Total clicks = 11 20 The Legacy of Jesus (El Legado de Jesús) Total clicks = 1 20 Be With Me Where I Am (Está Conmigo Donde Estoy) Total clicks = 3  
  4. Barand's post in Problem displaying database attribute inside a javascript popup was marked as the answer   
    You need to a way for your js function to specify which popup to show.
    One way would be to pass the room id in the function call
    onclick = "myFunction(xx)"
    and to append the room id to your ids to make them unique
    id="mypopupxx"
     
  5. Barand's post in Using row_number on attribute to only return 5 rows was marked as the answer   
    Another way to it is to forget about row_number() OVER etc and, instead, use the simpler
    SELECT ... , substring_index(GROUP_CONCAT(f.description separator ' &bull; '), ' &bull; ', 5) as rmfac to get the whole list of facilies then select the first 5
  6. Barand's post in How can I generate Class Position? was marked as the answer   
    try
    foreach ($res as $r) { if (!isset($data[$r['subjectname']])) { $data[$r['subjectname']]['students'] = []; } $position = ordinal($r['rank']); $data[$r['subjectname']]['students'][] = [ 'name' => $r['stname'], 'score' => $r['score'], 'rank' => $position ]; }  
  7. Barand's post in Not getting the needed values was marked as the answer   
    Sorry, I forgot to explain your probems
    There are no values in the class_id column that matche a column value in subj_levels column ("58100" != "58100, 47270") For find_in_set() to work, the values should be comma-separated, not comma-space-separated.
  8. Barand's post in Any need of this SQLi filtering rules? was marked as the answer   
    If you use prepared queries correctly, with placeholders for user-supplied data, you don't need that code - the values will not be embedded in the SQL code.
  9. Barand's post in Group Concat code not working as expected - and only showing 1 result was marked as the answer   
    When you use an agregation function (like SUM() or GROUP_CONCAT() ) without a GROUP BY clause, you get a single aggregation for the whole table.
  10. Barand's post in "New posts" was marked as the answer   
    Do I take it that a new image is one that is less than 2 weeks old?
    $day = date('Y-m-d', strtotime("2023-08-30 16:03:32")); if($day > date('Y-m-d', strtotime('-2 weeks'))){ echo "img src='https://i.imgur.com/0rlIlUD.gif'"; } @requinix - I see what you mean
  11. Barand's post in SQL statement with multiple joins - unknown column error was marked as the answer   
    You don't need any data from the booking table so the last join can go.
    At present your query does not know which rooms are booked, and when, as there is no join between room and room_booking tables. Your join to the room_booking table should therefore be ON r.room_id = rb.room_id
    How do you know what facilities a room has? There is no room_id in the room_facility table. Instead you have a size id???
    Your SELECT has no room_id or room_number so how will you identify the rooms in the results?
  12. Barand's post in Access single array element was marked as the answer   
    For the "[0]" to be needed then the json data would need to be
    [{ "id": 1, "item_id": 19, "min_qty": 1, "max_qty": 499, "GBP": 500, "USD": 750, "CAD": 875 }] with the outer [..] to make it an array.
  13. Barand's post in How to make visible of unvisible error while inserting data into mariadb database? was marked as the answer   
    One way is not to turn off the error reporting...
     
     
  14. Barand's post in Validating password characters was marked as the answer   
    Do your database , table and db connection all share the same utf8 encoding?
  15. Barand's post in Ajax log on handler wrapping redirected to page in response content was marked as the answer   
    When you send an ajax request to a page, all output then goes into the response that is returned. (ie what you would see if you called that page in your browser is the reponse (which you can use to your advantage to test ajax responders).
    Remove the location header from the responder code and do the redirect in the calling page when you receive a succesful response.
  16. Barand's post in Current password hashing standard was marked as the answer   
    password_hash() and password_verify()
  17. Barand's post in Duplicating Mysql Table rows but also updating some content was marked as the answer   
    Start with
    SELECT q.id , q.version FROM quote q JOIN ( SELECT client_id , max(version) as version FROM quote WHERE client_id = 15 ) latest USING (client_id, version); +----+---------+ | id | version | +----+---------+ | 71 | 6 | +----+---------+ Now you know that for client #15 the latest quote has id = 71 and its version is 6.
    Duplicate quote #71, giving the dupe a verion of 7, and duplicate the items for #71 with the quote_id of the new duped quote.
  18. Barand's post in Sql statement join question was marked as the answer   
    Something like this? ...
     
    SELECT j.id as job_id , j.name , count(q.id) as quotes FROM job j LEFT JOIN quote q ON j.id = q.job_id GROUP BY j.id  
  19. Barand's post in [Suggestions] - Ordering Items Dynamically was marked as the answer   
    -- first UPDATE thetable SET display_order = display_order + 1 WHERE display_order >= 2; -- then INSERT INTO thetable (item_name, display_order) VALUES ('Item 4', 2);  
  20. Barand's post in Build multidimentional array from select was marked as the answer   
    Oops!
    FETCH_GROUP should be FETCH_ASSOC.
    You also need to change the order of your selected columns so that the first two are the ones you are using as the keys, then the array_slice takes the rest..
  21. Barand's post in For each loop not getting all data was marked as the answer   
    Shouldn't that be
    if(!isset($data[$item['sectionName']])){ ^ What is the relevance of the data you posted to the code?
  22. Barand's post in More efficient rounding calculator was marked as the answer   
    The code you posted was using PHP variable names. ($days, $weeks)
    intdiv (x, y) == floor(x/y)
  23. Barand's post in On duplicate key update always inserting new row was marked as the answer   
    You should be getting a mysql error - you have 7 placeholders but only passing 6 values in the execute. The way you have defined it you need to pass the $_POST['quotename'] twice.
    A better way is
    ... ON DUPLICATE KEY UPDATE name=VALUES(name) telling it to use the same value as in the VALUES clause. The you only need provide the name once.
    As for your problem, what has to be duplicated to throw a duplicate key error? Your id will be auto_incremented so that won't be duplicated.
  24. Barand's post in Insert Ignore was marked as the answer   
    Just alter the table to add the unique constraint. Run this query...
    ALTER TABLE `tablename` ADD UNIQUE INDEX `unq_user_date` (`user_id` ASC, `timestamp` ASC); Checking if it exists first is the worst way to do it.
  25. Barand's post in String help was marked as the answer   
    One way...
    $str = "1 x MAKE: Behringer, 1 x MODEL: X-32, 1 x Problem with unit: Not powering on"; $a = explode(': ', $str); unset ($a[0]); foreach ($a as $b) { $results[] = explode(',', $b)[0]; } echo '<pre>results = ' . print_r($results, 1) . '</pre>'; output...
    results = Array ( [0] => Behringer [1] => X-32 [2] => Not powering on )  
×
×
  • 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.