-
Who's Online 1 Member, 1 Anonymous, 58 Guests (See full list)
All Activity
- Today
-
you are constantly changing data types, names, and adding features. this makes writing code extremely wasteful. you need to define everything possible, before you write any code. you also need to define what inputs you have for any operation, what processing you are going to do based on those inputs, and what result or output you are going to produce. as to a simple, straightforward solution, i recommend that you read the suggestions in the previous thread, about building an array with the dates as the array index and the values being whatever you are trying to produce. in that thread, the array was for the special events for the calendar being displayed. in this thread, the array is for the requested date range and the price for each day in that range. the inputs to this code are the start and end dates of the request, the standard week day and week end prices, and the seasonal pricing. you would start by creating an array using the request range of dates as the array index. you would fill in the array with the week day and week end prices. you would then replace any price that matches the seasonal pricing data. when you are done, you will have an array with all the days of the request as the index, and the price for each day. you can then just sum the prices to get the total. here's a procedural function that gets the seasonal prices, given the request start and end date - // get seasonal prices between start and end date function get_prices($start,$end,$seasonPrices) { $result = []; foreach($seasonPrices as $row) { // keep entries that match the requested start/end // SeasonEnd >= start AND end >= SeasonStart if($row->SeasonEnd >= $start && $end >= $row->SeasonStart) { // expand this entry and only keep the values between the start and end (for the case of spanning the start or end date) $entry = Cal::bookedArray($row->SeasonStart, $row->SeasonEnd); foreach($entry as $date) { // if date between start and end, keep it if($start <= $date && $date <= $end) { $result[$date] = $row->SeasonPrice; } } } } return $result; } you can use array_replace() with the array you are building and the array returned by the above function to replace the standard prices in that array with the seasonal prices.
-
So far this is what code I have if(!empty($standardRates)) { foreach($standardRates as $row) { if($row->SeasonName == 'Standard Weekday') { $standardRate['Weekday'] = $row->SeasonPrice; } if($row->SeasonName == 'Standard Weekend') { $standardRate['Weekend'] = $row->SeasonPrice; } } } if(!empty($setPrices)) { $i = 0; foreach($setPrices as $row) { $specialRate[$i]['start'] = $row->SeasonStart; $specialRate[$i]['end'] = $row->SeasonEnd; $specialRate[$i]['price'] = $row->SeasonPrice; $i++; } } $cost = array(); foreach($flatRequest as $key => $val) { for($i=0; $i<count($specialRate); $i++) { if(in_array($val, Cal::bookedArray($specialRate[$i]['start'], $specialRate[$i]['end']))) { array_push($cost, $specialRate[$i]['price']); } } if(empty($specialRate)) { if(date('l', strtotime($val)) == 'Saturday' || date('l', strtotime($val)) == 'Sunday') { array_push($cost, $standardRate['Weekend']); } else { array_push($cost, $standardRate['Weekday']); } } } This doesn't work though, $cost is empty
-
I'll just put what i am trying to achieve instead of the code i am using I have 2 arrays with stored days and prices # Standard Days Array ( [0] => stdClass Object ( [name] => Standard Weekday [price] => 60 ) [1] => stdClass Object ( [name] => Standard Weekend [price] => 80 ) ) # Special Days Array ( [0] => Array ( [start] => 2025-02-21 [end] => 2025-03-03 [price] => 100 ) [1] => Array ( [start] => 2025-04-11 [end] => 2025-04-27 [price] => 100 ) [2] => Array ( [start] => 2025-05-02 [end] => 2025-05-05 [price] => 110 ) [3] => Array ( [start] => 2025-05-23 [end] => 2025-06-01 [price] => 110 ) [4] => Array ( [start] => 2025-07-18 [end] => 2025-09-01 [price] => 120 ) [5] => Array ( [start] => 2025-10-24 [end] => 2025-11-02 [price] => 110 ) [6] => Array ( [start] => 2025-12-19 [end] => 2026-01-04 [price] => 120 ) ) I want to get the prices from those arrays for each day from the selected dates, so from 1st May 2025 to 8th May 2025 would look like this # Selected Days Array ( [0] => 2025-05-01 [1] => 2025-05-02 [2] => 2025-05-03 [3] => 2025-05-04 [4] => 2025-05-05 [5] => 2025-05-06 [6] => 2025-05-07 [7] => 2025-05-08 ) so for each of the Selected Days if the date is not in the Special Days array it will give me the price of the standard weekday or weekend, If it is in the special date it will give me that instead. Because there are no special dates in the selected days it would calculate (5x60)+(2x80) so give a total of 460. Its when there is special dates where i am having the issue, how can i check each selected day in the special days array and get the price for that array
-
Leloror joined the community
- Yesterday
-
Your wording and examples are a bit all over the place, I believe you're trying to filter an array, and then manipulate any specific ones that match particular date. Right? So, if 5/5/25 is a day with a special rate, and is within the date range provided by the user, use the "special" price? You can use array_map to manipulate the items that match a specific date. An example of it being used for only one "special" date - May 5 2025 $dates = [ '2025-05-01', '2025-05-02', '2025-05-03', '2025-05-04', '2025-05-05', ]; $specialDate = '2025-05-05'; $specialPrice = 8.00; // The special price to apply ONLY on $specialDate $priceUpdateCallback = function ($item) use ($specialDate, $specialPrice) { $element = ["date" => $item, "price" => 10]; if ($item == $specialDate) { $element['date'] = $specialDate; $element['price'] = $specialPrice } return $element; }; $result = array_map('priceUpdateCallback', $dates); echo "<pre>", print_r($result), "</pre>"; Should give you something like Array ( .............Array ( [date] => 2025-05-05 [price] => 8 ) )
-
for the posted information, the requested date range of 2025-05-06 to 2025-05-22 doesn't match any of the $seasonPrices data. It starts one day after the end of the May Day range and ends one day before the start of the Summer half-term range. it should use the base/default price for every day. since you are using a standard date format, you can directly perform date comparisons by order, as mentioned in the previous thread. you can directly compare a date to the $seasonPrices SeasonStart and SeasonEnd values to find if it is between a date range. i would write a function/class-method that accepts a date input, loops over the $seasonPrices data, returns the first price that is between the SeasonStart and SeasonEnd values, or returns zero (or some other easily detected value) if it reaches the end without finding a match. as a procedural function, something like - function get_price($date,$seasonPrices) { foreach($seasonPrices as $row) { // date between start and end if($row->SeasonStart <= $date && $date <= $row->SeasonEnd) { return $row->SeasonPrice; } } // no match return 0; }
-
I am trying to get values from an array with a date range This is the var_dump assuming from date is 06 May 2025 and to date is 22 May 2025 [0]=> string(10) "2025-05-06" [1]=> string(10) "2025-05-07" [2]=> string(10) "2025-05-08" [3]=> string(10) "2025-05-09" [4]=> string(10) "2025-05-10" [5]=> string(10) "2025-05-11" [6]=> string(10) "2025-05-12" [7]=> string(10) "2025-05-13" [8]=> string(10) "2025-05-14" [9]=> string(10) "2025-05-15" [10]=> string(10) "2025-05-16" [11]=> string(10) "2025-05-17" [12]=> string(10) "2025-05-18" [13]=> string(10) "2025-05-19" [14]=> string(10) "2025-05-20" [15]=> string(10) "2025-05-21" [16]=> string(10) "2025-05-22" It then searches the following array $count = 0; foreach($seasonPrices as $row) { $price[$count]['name'] = $row->SeasonName; $price[$count]['days'] = implode(',', Cal::bookedArray($row->SeasonStart, $row->SeasonEnd)); $price[$count]['price'] = $row->SeasonPrice; $count++; } unset($count); [2]=> array(3) { ["name"]=> string(16) "Spring half-term" ["days"]=> string(120) "2025-02-21,2025-02-22,2025-02-23,2025-02-24,2025-02-25,2025-02-26,2025-02-27,2025-02-28,2025-03-01,2025-03-02,2025-03-03" ["price"]=> string(3) "100" } [3]=> array(3) { ["name"]=> string(6) "Easter" ["days"]=> string(186) "2025-04-11,2025-04-12,2025-04-13,2025-04-14,2025-04-15,2025-04-16,2025-04-17,2025-04-18,2025-04-19,2025-04-20,2025-04-21,2025-04-22,2025-04-23,2025-04-24,2025-04-25,2025-04-26,2025-04-27" ["price"]=> string(3) "100" } [4]=> array(3) { ["name"]=> string(7) "May Day" ["days"]=> string(43) "2025-05-02,2025-05-03,2025-05-04,2025-05-05" ["price"]=> string(3) "110" } [5]=> array(3) { ["name"]=> string(16) "Summer half-term" ["days"]=> string(109) "2025-05-23,2025-05-24,2025-05-25,2025-05-26,2025-05-27,2025-05-28,2025-05-29,2025-05-30,2025-05-31,2025-06-01" ["price"]=> string(3) "110" } [6]=> array(3) { ["name"]=> string(6) "Summer" ["days"]=> string(505) "2025-07-18,2025-07-19,2025-07-20,2025-07-21,2025-07-22,2025-07-23,2025-07-24,2025-07-25,2025-07-26,2025-07-27,2025-07-28,2025-07-29,2025-07-30,2025-07-31,2025-08-01,2025-08-02,2025-08-03,2025-08-04,2025-08-05,2025-08-06,2025-08-07,2025-08-08,2025-08-09,2025-08-10,2025-08-11,2025-08-12,2025-08-13,2025-08-14,2025-08-15,2025-08-16,2025-08-17,2025-08-18,2025-08-19,2025-08-20,2025-08-21,2025-08-22,2025-08-23,2025-08-24,2025-08-25,2025-08-26,2025-08-27,2025-08-28,2025-08-29,2025-08-30,2025-08-31,2025-09-01" ["price"]=> string(3) "120" } [7]=> array(3) { ["name"]=> string(16) "Autumn half-term" ["days"]=> string(120) "2025-10-24,2025-10-25,2025-10-26,2025-10-26,2025-10-27,2025-10-28,2025-10-29,2025-10-30,2025-10-31,2025-11-01,2025-11-02" ["price"]=> string(3) "110" } [8]=> array(3) { ["name"]=> string(10) "Christmas " ["days"]=> string(186) "2025-12-19,2025-12-20,2025-12-21,2025-12-22,2025-12-23,2025-12-24,2025-12-25,2025-12-26,2025-12-27,2025-12-28,2025-12-29,2025-12-30,2025-12-31,2026-01-01,2026-01-02,2026-01-03,2026-01-04" ["price"]=> string(3) "120" } [9]=> array(3) { ["name"]=> string(16) "Spring half-term" ["days"]=> string(109) "2026-02-20,2026-02-21,2026-02-22,2026-02-23,2026-02-24,2026-02-25,2026-02-26,2026-02-27,2026-02-28,2026-03-01" ["price"]=> string(3) "100" } [10]=> array(3) { ["name"]=> string(6) "Easter" ["days"]=> string(197) "2026-04-02,2026-04-03,2026-04-04,2026-04-05,2026-04-06,2026-04-07,2026-04-08,2026-04-09,2026-04-10,2026-04-11,2026-04-12,2026-04-13,2026-04-14,2026-04-15,2026-04-16,2026-04-17,2026-04-18,2026-04-19" ["price"]=> string(3) "100" } [11]=> array(3) { ["name"]=> string(7) "May Day" ["days"]=> string(43) "2026-05-01,2026-05-02,2026-05-03,2026-05-04" ["price"]=> string(3) "110" } [12]=> array(3) { ["name"]=> string(16) "Summer half-term" ["days"]=> string(109) "2026-05-22,2026-05-23,2026-05-24,2026-05-25,2026-05-26,2026-05-27,2026-05-28,2026-05-29,2026-05-30,2026-05-31" ["price"]=> string(3) "110" } [13]=> array(3) { ["name"]=> string(6) "Summer" ["days"]=> string(516) "2026-07-17,2026-07-18,2026-07-19,2026-07-20,2026-07-21,2026-07-22,2026-07-23,2026-07-24,2026-07-25,2026-07-26,2026-07-27,2026-07-28,2026-07-29,2026-07-30,2026-07-31,2026-08-01,2026-08-02,2026-08-03,2026-08-04,2026-08-05,2026-08-06,2026-08-07,2026-08-08,2026-08-09,2026-08-10,2026-08-11,2026-08-12,2026-08-13,2026-08-14,2026-08-15,2026-08-16,2026-08-17,2026-08-18,2026-08-19,2026-08-20,2026-08-21,2026-08-22,2026-08-23,2026-08-24,2026-08-25,2026-08-26,2026-08-27,2026-08-28,2026-08-29,2026-08-30,2026-08-31,2026-09-01" ["price"]=> string(3) "120" } [14]=> array(3) { ["name"]=> string(16) "Autumn half-term" ["days"]=> string(120) "2026-10-23,2026-10-24,2026-10-25,2026-10-25,2026-10-26,2026-10-27,2026-10-28,2026-10-29,2026-10-30,2026-10-31,2026-11-01" ["price"]=> string(3) "110" } [15]=> array(3) { ["name"]=> string(10) "Christmas " ["days"]=> string(186) "2026-12-18,2026-12-19,2026-12-20,2026-12-21,2026-12-22,2026-12-23,2026-12-24,2026-12-25,2026-12-26,2026-12-27,2026-12-28,2026-12-29,2026-12-30,2026-12-31,2027-01-01,2027-01-02,2027-01-03" ["price"]=> string(3) "120" } If the requested dates are present in the price array i then need to extract the price for each day to put into an array to calculate the total cost if(in_array($rested, $prices) { array_push($cost, $prices[]['price']; } echo array_sum($cost); I have tried for loops, for each loops, array_diff, array_intersect and anything else i could think of put cant get it to work properly. Any help would me much appreciated The code i have put isnt the exact code i have now as i have been trying all day and its changed every time i've tried something else. The code i have right now only adds 2 prices to the cost array even though there more than 2 dates in the requested dates Please Help!! Thanks in advance
-
I managed to sort it, my question was a bit misleading. I had a calendar that was only showing 1 booked date range but that was because i had used = instead of == so now it shows all bookings
-
I realised I should add…. I have actually also established that this is unlikely to be a php (or more generally a ‘dynamically created content’) issue. I tried converting some of my files into statically generated files, ie nothing to do with PHP. My XSL files were still not cached by the browser properly. So this issue right now actually seems unrelated to PHP. It’s some kind of inconsistency between browsers’ treatment of different file types.
- Last week
-
Remilo9868 joined the community
-
marvia joined the community
-
Thank you @gizmola - appreciate your time to reply. Unfortunately don’t have a Mac, but will looked into getting some help with this and also the “tail” suggestion .
-
DigitizingBuddy joined the community
-
There are a few different ways to process the stats based on what game and mod you are running. The one that is giving me the error is based on savestate 1 which continues from the last saved game log file. Savestate 0 runs without errors, but processes every game log file all over again every time. This is the from the batch file I use to tun the stats: C:\xampp\php\php.exe -f "C:\xampp\htdocs\q3eplus.servequake.com\vsp.php" -- -l q3a-xp -p savestate 1 "D:\Quake III Arena\excessiveplus\logs\server_mp.log"
-
Suyadi's comment is factually accurate. The code expects the constant value LOG_READ_SIZE, and it is not defined. WIth that said, often utility applications come with instructions on how they should be configured, it looks like this might be the case for the application. Check instructions and see if there is a configuration file that needs to exist in a particular place. Many applications are distributed with a file with default settings that needs to be copied and renamed.
-
That means it's not defined anywhere on that file so PHP can't find it. My suggestion would be to raise this issue to the developer of that script as the developer seems forgot to define that constant in their code. Those LOG_READ_SIZE constant used to set the offset of the fseek() and we don't know how big he set those number. my wild guess is as big as the log file size, so: defined('LOG_READ_SIZE') or define('LOG_READ_SIZE', filesize($logfilePath)); $seekResult = fseek($parser->logFileHandle, -LOG_READ_SIZE, SEEK_CUR);
-
Invalid password when using password_verify
Suyadi replied to rwahdan1978's topic in PHP Coding Help
This is correct, the length of string produced by password_hash() with default algorithm (bcrypt, as of now) is always 60 characters. So if you do password_hash('mypassword', PASSWORD_DEFAULT); and your database column can only store less than 60 characters, it will be truncated with some error being thrown -
Lol, me too That should be: $sql = $pdoObject->prepare($qry); $result = $sql->execute(['exp' => null, 'email' => $myusername]); As the PDOStatement::execute only accept one parameter. Reference: https://www.php.net/manual/en/pdostatement.execute.php
-
Trying to use GLOB function to create gallery.
Suyadi replied to BluApple's topic in PHP Coding Help
HI, you can try to use glob() with the __DIR__ constant. For example: $currentDir = __DIR__; // this is your current directory So, if you want to scan images inside your sub-directory, let's say the 'gallery' directory, just do: $subDirectory = 'gallery'; $images = glob($currentDir . '/' . $subDirectory . '/*.{jpg,jpeg,gif,png,bmp,webp}', GLOB_BRACE); Check the result: print_r($images); -
$timezone = 'Asia/Jakarta'; // Change this $dbTime = '2025-04-26 20:30:00'; $dbTime = DateTime::createFromFormat('Y-m-d H:i:s', $dbTime, new DateTimeZone($timezone)); $now = new DateTime('now', new DateTimeZone($timezone)); print_r($dbTime->diff($now)); print_r($now->diff($dbTime)); Result: DateInterval Object ( [y] => 0 [m] => 0 [d] => 5 [h] => 2 [i] => 13 [s] => 10 [f] => 0.828 [invert] => 0 [days] => 5 [from_string] => ) DateInterval Object ( [y] => 0 [m] => 0 [d] => 5 [h] => 2 [i] => 13 [s] => 10 [f] => 0.828 [invert] => 1 [days] => 5 [from_string] => )
-
How to get the current time and add 10 minutes?
Suyadi replied to rwahdan1978's topic in PHP Coding Help
$timezone = 'Asia/Jakarta'; // Change this $date = new DateTime('now',new DateTimeZone($timezone)); $date->modify('+10 minute'); echo $date->format('Y-m-d H:i:s'); -
Suyadi joined the community
-
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
Adding question marks helped! Silly me! 😧 Using barands code displays all picures on the smae page while i'm trying to create a folder. Http://inflorescence.infy.uk/tryout.php -
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
The file is in the main folder where to upload the website. Let me try to use the correct inclusief code. That might help. I'll get back as soon as i've tried that. -
I'm using a game stats processor called VSP stats which parses game logs and displays the output to a web page. The issue I'm having is that it stops processing the logs with the following error: PHP Fatal error: Uncaught Error: Undefined constant "LOG_READ_SIZE". The line of code that is causing the error: $seekResult = fseek($parser->logFileHandle, -LOG_READ_SIZE, SEEK_CUR); Server is on Windows 11 Apache 2.4.58 PHP 8.2.12.
-
janampatri joined the community
-
what exactly is the single $booked data for vs the array of $bookings? i have the following recommendations - use a standard yyyy-mm-dd date format. if/when you store the data in a database, this will be necessary to allow queries to compare dates by order. it will also make your current code easier to understand. the bookings data should be stored in a database table. you should have a start_date and an end_date input to the code on this page, so that the code will work for any date range, from multiple years down to a single month. you are looping over the $res array for every date being displayed, currently for the whole year. i recommend that you instead produce an array using the date as the array index, and the stored value indicating what is occurring on that date, limited to be between the start_date and end_date mentioned above. as you are producing the output, you can simply test, no loop required, if there is an entry in this array, using isset(), then get the stored value if there is one, and use it to control what you output for the date. with a little conditional logic, you don't need separate logic to deal with the first (partial) week, then repeat that logic for the remainder of each month. if you use php's short-open-print tag and leave out the ; right before a closing tag, you can use simple syntax like - <?=$some_var?> to output values in the markup. use php's DateInterval and DatePeriod to expand the booking date ranges. here's example code for item #7 - $start = new DateTime($start); $end = new DateTime($end); $end = $end->modify('+1 day'); // include the end point $interval = new DateInterval('P1D'); // 1 day $daterange = new DatePeriod($start, $interval ,$end); $dates = array(); foreach($daterange as $date){ $dates[] = $date->format("Y-m-d"); }
-
Trying to use GLOB function to create gallery.
Psycho replied to BluApple's topic in PHP Coding Help
First, your two includes at the top and bottom of the page are not within correct PHP tags. Need a ? before the starting PHP. The DIV in your code is in the HTML source, but there is nothing within it. That would seem to indicate that there was no content in the $images array. I'm guessing that the path you provided to the glob function is not correct. Where is the 'photography' folder in relation to where the php file is being executed? -
In a past life, have experience turning dynamic, user generated content via a web page into print-ready PDFs for commercial printing. In that case, the user input on the web forms was converted into PostScript code that was then run through a processing engine (my expertise was in the postscript programming). So, when I had a need to generate PDFs as a PHP hobbyist, I looked for a solution where I could "program" the creation of the PDF in the same way as I did with PostScript. I ended up using the FPDF Library. If you have fairly rigid constraints on the layout of the content, this could be an option. Instead of generating an HTML page and running that through something to convert it to a PDF, this library allows you to create a PFD file in much the same way you would create a web page. I.e. determine "where" on the page you want to put an element, define things like color, font, and then place the elements on the page. However, there is another, simpler option. Instead of emailing the user a PDF, just send the user a link. That link would be to a web page of their quote and then the user can print the web page quote to PDF, the printer, or however they want. I think most shopping sites I use have this approach if I want to print the invoice. This much simpler and less moving parts, IMO.
-
Trying to use GLOB function to create gallery.
BluApple replied to BluApple's topic in PHP Coding Help
-
Trying to use GLOB function to create gallery.
gizmola replied to BluApple's topic in PHP Coding Help
When people are using tutorials to try and create PHP based features, there are pitfalls, the potential for misunderstandings and the possibility of error. We need to see what your actual code is. The only exception is in the case of passwords, keys etc. Those should be replaced. So we would need to see your code and the actual path you used in your code. The operating system, hosting location etc, is also important information in many cases. It sounds like you have error turned off at present, and for development, errors need to be turned on, so you can see what they are. It looks like your code has one or more errors in it, and that is why you are getting a blank page, but if errors are turned off, you can't see what the error message is.