
Andy2024
Members-
Posts
23 -
Joined
-
Last visited
Everything posted by Andy2024
-
I've managed to sort it and it works perfectly. I've also put it into a class, here is code if anyone wants to use it. Thank you for all your help! class Calendar { public static function bookedArray($strDateFrom,$strDateTo) { $aryRange = []; $iDateFrom = strtotime($strDateFrom); $iDateTo = strtotime($strDateTo); if ($iDateTo >= $iDateFrom) { array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry while ($iDateFrom<$iDateTo) { $iDateFrom += 86400; // add 24 hours array_push($aryRange, date('Y-m-d', $iDateFrom)); } } return $aryRange; } public static function flattenCalendar($array) { $flatArray = []; array_walk_recursive($array, function($value) use (&$flatArray) { $flatArray[] = $value; }); return $flatArray; } public static function estimatePrice($checkin, $checkout, $stdArray, $specArray) { $requestDates = self::bookedArray($checkin, $checkout); $specialRate = array(); $standardRate = array(); $cost = array(); //return var_dump($requestDates); if(!empty($stdArray)) { foreach($stdArray as $row) { if($row->SeasonName == 'Standard Weekday') { $standardRate['Weekday'] = $row->SeasonPrice; } if($row->SeasonName == 'Standard Weekend') { $standardRate['Weekend'] = $row->SeasonPrice; } } } if(!empty($specArray)) { $i = 0; foreach($specArray as $row) { $specialRate[$i]['start'] = $row->SeasonStart; $specialRate[$i]['end'] = $row->SeasonEnd; $specialRate[$i]['price'] = $row->SeasonPrice; $i++; } } $specialCount = count($specialRate); $standardCount = count($stdArray); $flatRequest = self::flattenCalendar($requestDates); // Reqested Dated into One Array $cost = array(); $specialCost = array(); $days = count($flatRequest); foreach($flatRequest as $key => $val) { $specialDays = 0; for($i=0; $i<count($specialRate); $i++) { $range = self::bookedArray($specialRate[$i]['start'], $specialRate[$i]['end']); array_pop($range); if(in_array($val, $range)) { array_push($specialCost, $specialRate[$i]['price']); $specialDays++; unset($flatRequest[$key]); } } } array_pop($flatRequest); foreach($flatRequest as $key => $val) { if( date('l', strtotime($val)) == 'Saturday' || date('l', strtotime($val)) == 'Sunday' ) { array_push($cost, $standardRate['Weekend']); } else { array_push($cost, $standardRate['Weekday']); } } if(!empty($cost) && !empty($specialCost)) { return array_sum(array_merge($cost, $specialCost)); } elseif(!empty($specialCost) && empty($cost)) { array_pop($specialCost); return array_sum($specialCost); } else { return array_sum($cost); } } }
-
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
-
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'm Trying to create a booking/availability calendar that shows a full 12 months bookings/availability. I have come up with the following so far $publicHolidays = array(date('j-n-Y', strtotime('1st January 2025')), date('j-n-Y', strtotime('18th April 2025')), date('j-n-Y', strtotime('21st April 2025')), date('j-n-Y', strtotime('5th May 2025')), date('j-n-Y', strtotime('26th May 2025')), date('j-n-Y', strtotime('25th August 2025')), date('j-n-Y', strtotime('25th December 2025')), date('j-n-Y', strtotime('26th December 2025'))); $bookings = array(array('Check-In' => '1-1-2025', 'Check-Out' => '7-1-2025'), array('Check-In' => '3-2-2025', 'Check-Out' => '13-2-2025'), array('Check-In' => '2-3-2025', 'Check-Out' => '25-3-2025'), array('Check-In' => '2-4-2025', 'Check-Out' => '21-4-2025'), array('Check-In' => '6-6-2025', 'Check-Out' => '9-6-2025'), array('Check-In' => '2-9-2025', 'Check-Out' => '5-9-2025'), array('Check-In' => '3-11-2025', 'Check-Out' => '30-11-2025')); foreach($bookings as $row) { $res[] = Cal::bookedArray($row['Check-In'],$row['Check-Out']); } $booked = Cal::bookedArray('1-4-2025','7-4-2025'); $month = '1'; $year = date('Y'); for($m=$month;$m<13;$m++) { $timestamp = mktime(0, 0, 0, $m, 1, $year); $daysInMonth = date("t", $timestamp); $firstDay = date("N", $timestamp); if($m == date('m')) { $featured =' featured'; } else { $featured=''; } ?> <div class="col-xl-4 col-lg-6" data-aos="fade-up" data-aos-delay="100"> <div class="pricing-item p-0<?php echo $featured;?>"> <h3 class="mb-0 pt-5"><?php echo date('F', mktime(0,0,0,$m)); ?></h3> <table class="table table-bordered m-0"> <tr> <th>Mon</th> <th>Tue</th> <th>Wed</th> <th>Thu</th> <th>Fri</th> <th>Sat</th> <th>Sun</th> </tr> <?php $dayCount = 1; ?> <tr> <?php for ($i = 1; $i <= 7; $i++) { $date = "$dayCount-$m-$year"; if ($i < $firstDay) { echo "<td></td>"; } else { $date = "$dayCount-$m-$year"; if(date('l', strtotime($date)) == 'Saturday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(date('l', strtotime($date)) == 'Sunday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(in_array($date, $publicHolidays) && !in_array($date, $booked)) { $cellBg="class='table-warning'"; } else { $cellBg="class='table-light'"; } foreach($res as $key => $val) { /* $firstday = reset($val); $lastday = end($val); if($date = $firstday) { $cellBg="class='table-primary'"; } elseif(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } elseif($date = $lastday) { $cellBg="class='table-primary'"; } */ if(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } } echo "<td $cellBg>$dayCount</td>"; $dayCount++; } } echo "</tr>"; while ($dayCount <= $daysInMonth) { echo "<tr>"; for ($i = 1; $i <= 7 && $dayCount <= $daysInMonth; $i++) { $date = "$dayCount-$m-$year"; if(date('l', strtotime($date)) == 'Saturday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(date('l', strtotime($date)) == 'Sunday' && !in_array($date, $booked)) { $cellBg="class='table-info'"; } elseif(in_array($date, $publicHolidays) && !in_array($date, $booked)) { $cellBg="class='table-warning'"; } else { $cellBg="class='table-light'"; } foreach($res as $key => $val) { /* $firstday = reset($val); $lastday = end($val); if($date = $firstday) { $cellBg="class='table-primary'"; } elseif(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } elseif($date = $lastday) { $cellBg="class='table-primary'"; } */ if(in_array($date, array_splice($val,1,-1))) { $cellBg="class='table-danger'"; } } echo "<td $cellBg>$dayCount</td>"; $dayCount++; } ?> </tr> <?php } ?> </table> </div> </div> <?php } Its reading the arrays, drawing the calendar and colorizing the weekends, public holidays and bookings. What i need is to change the check-in and check-out date color to reflect what they are. I've commented out what ive been trying but it isnt working. here is the bookedarray function if anyone needs it public static function bookedArray($strDateFrom,$strDateTo) { $aryRange = []; $iDateFrom = strtotime($strDateFrom); $iDateTo = strtotime($strDateTo); if ($iDateTo >= $iDateFrom) { array_push($aryRange, date('j-n-Y', $iDateFrom)); // first entry while ($iDateFrom<$iDateTo) { $iDateFrom += 86400; // add 24 hours array_push($aryRange, date('j-n-Y', $iDateFrom)); } } return $aryRange; } Any help would be much appreciated or even a pointer as to were I could find a solution Thanks in advance
-
Bit of a breakthrough I've altered the PHP to if(!empty($data['legend'])) { foreach($data['legend'] as $r1) { if(isset($r1->Name)) { $sales = $this->_query->get_sales_count($r1->IdService); if(!empty($sales)) { foreach($sales as $r2) { $count[$r1->Name][] = $r2->Sales; } $legend[] = array('label' => $r1->Name, 'backgroundColor' => $r1->GraphColor, 'data' => implode(',',$count[$r1->Name])); } } } } and that has given me [{"label":"Installation","backgroundColor":"#2bca2d","data":"8,19,11,3,49"},{"label":"Repair","backgroundColor":"#cfca3a","data":"1,3,7"}] which looks ok until its placed in the char then it adds everything to the wrong month and only 1 item per month
-
I tried that but still gives the same results
-
I have had to go about it a totally different way because I need figures for each job type so have got this "SELECT ".PREFIX."tservices.IdService, ".PREFIX."tservices.Name, ".PREFIX."tservices.GraphColor, ".PREFIX."tprojects.Service, COUNT(".PREFIX."tprojects.IdProject) as Sales, ".PREFIX."tprojects.Finish FROM ".PREFIX."tservices LEFT JOIN ".PREFIX."tprojects ON ".PREFIX."tservices.IdService = ".PREFIX."tprojects.Service WHERE ".PREFIX."tservices.InGraph = '1' GROUP BY MONTH(".PREFIX."tprojects.Finish), YEAR(".PREFIX."tprojects.Finish) ORDER BY ".PREFIX."tprojects.Finish DESC LIMIT 0, 12" Then the PHP is if(!empty($data['legend'])) { foreach($data['legend'] as $r1) { if(isset($r1->Name)) { $sales = $this->_query->get_sales_count($r1->IdService); if(!empty($sales)) { foreach($sales as $r2) { $count[] = $r2->Sales; } $legend[] = array('label' => $r1->Name, 'backgroundColor' => $r1->GraphColor, 'data' => implode(',',$count)); } } } } But the json its outputting [{"label":"Installation","backgroundColor":"#2bca2d","data":"8,19,11,3,49"},{"label":"Repair","backgroundColor":"#cfca3a","data":"8,19,11,3,49,1,3,7"}] instead of [{"label":"Installation","backgroundColor":"#2bca2d","data":"8,19,11,3,49"},{"label":"Repair","backgroundColor":"#cfca3a","data":"1,3,7"}] Does anyone have any idea how to solve this? Thanks in advance
-
Sorted thanks I ended up putting if(!empty($counts->Counter) && !empty($counts->Month)) { array_push($sales, array('Count' => $counts->Counter, 'Month' => $counts->Month)); } At least its giving the correct count
-
Found an issue, i haven't converted the datetime string to sql datetime somewhere
-
i think it may be returning them on different rows in the array [0]=> array(2) { ["Count"]=> int(61) ["Month"]=> NULL } [1]=> array(2) { ["Count"]=> int(5) ["Month"]=> int(5) } } [0]is returning the count and [1] is returning the month (5) May!
-
Their are a total of 69 rows in table ".PREFIX."tprojects as per phpmyadmin
-
That is the issue because this also give the same result public function get_sales_count($id) { return $this->db->select("SELECT COUNT(".PREFIX."tprojects.IdProject) as Sales, MONTH(".PREFIX."tprojects.Start) AS Month FROM ".PREFIX."tprojects WHERE ".PREFIX."tprojects.IsActive = '1' AND ".PREFIX."tprojects.Service = '$id' GROUP BY MONTH(".PREFIX."tprojects.Start), YEAR(".PREFIX."tprojects.Start)"); } array(2) { [0]=> array(2) { ["Count"]=> int(61) ["Month"]=> NULL } [1]=> array(2) { ["Count"]=> int(5) ["Month"]=> int(5) } } I cannot understand where thus is coming from either because all entries are may 2024
-
I'm trying to get sales counts by month but having issues. Here is the dump array(2) { [0]=> object(stdClass)#80 (2) { ["Counter"]=> int(61) ["Month"]=> NULL } [1]=> object(stdClass)#81 (2) { ["Counter"]=> int(5) ["Month"]=> int(5) } } how would i get { ["Counter"]=> int(61) ["Month"]=> int(5) } Here is the code i am using MySQL public function get_sales_list() { return $this->db->select("SELECT * FROM ".PREFIX."tservices WHERE InGraph = '1'"); } public function get_sales_count($id) { return $this->db->select("SELECT COUNT(".PREFIX."tprojects.IdProject) as Sales FROM ".PREFIX."tprojects WHERE ".PREFIX."tprojects.IsActive = '1' AND ".PREFIX."tprojects.Service = '$id' GROUP BY MONTH(".PREFIX."tprojects.Start), YEAR(".PREFIX."tprojects.Start)"); } PHP $servGraph = $this->_query->get_sales_list(); if(isset($servGraph)) { $sales = array(); foreach($servGraph as $row) { $count = $this->_query->annual_sales($row->IdService); foreach($count as $key => $val) { array_push($sales, $val); } } } $data['sales-list'] = $sales; var_dump($data['sales-list']); Thanks in advance for any help or suggections
-
Ive modified the Simple PHP Shopping Cart from the phppot site but for some reason when the cart reaches 19 items it wont add anything else to it and i dont know why. Is their a limit within php how long a session array can be? Here is the code that adds each item to the array $cartItems = Session::get("cart_item"); $itemArray = array( 'ItemDesc' => $_POST["ItemDesc"], 'ItemCode' => $_POST["ItemCode"], 'ItemQty' => $_POST["ItemQty"], 'ItemAmount' => $_POST["ItemAmount"], 'ItemTotalAmount' => ($_POST["ItemQty"] * $_POST["ItemAmount"]), 'IdSupplier' => $_POST["IdSupplier"]); if(!empty($cartItems)) { if(in_array($itemArray["ItemCode"],array_keys($cartItems))) { foreach($cartItems as $k => $v) { if($itemArray["ItemCode"] == $k) { if(empty($cartItems[$k]["ItemQty"])) { $cartItems[$k]["ItemQty"] = 0; } $cartItems[$k]["ItemQty"] += $_POST["ItemQty"]; } } } else { $cartItems[] = array_merge($cartItems,$itemArray); } } else { $cartItems[] = $itemArray; } Session::set("cart_item", $cartItems); $counter = count(Session::get("cart_item")); Any help or suggestions would be greatly appreciated
-
Thanks you so much, i couldn't see the wood for the trees i'd put $cartItems = $itemArray; instead of $cartItems[] = $itemArray; before setting the session Session::set("cart_item", $cartItems);
-
Sorry am getting PH FLEXI FRAME EXTENDER FRAME 370373 1 210.92 210.92 So why is it putting everything on a new row!
-
I know its a different item because i cleared the session in case it was that but when i if(!empty(Session::get("cart_item"))) { print_r(Session::get("cart_item")); foreach(Session::get("cart_item") as $row) { print_r($row); } } for the session i'm getting Array ( [ItemDesc] => PH FLEXI FRAME EXTENDER FRAME [ItemCode] => 370373 [ItemQty] => 1 [price] => 210.92 [ItemTotalAmount] => 210.92 ) but for the row i'm getting PH FLEXI FRAME EXTENDER FRAME So where are the other keys and values going?
-
I'm trying to create a shopping cart but am having trouble retrieving the results and my head is about to explode. The array has been created because when i print_r or var_dump it i get Array ( [ItemDesc] => JOULE 300L AERO COIL [ItemCode] => 118710 [ItemQty] => 1 [price] => 4764.54 [ItemTotalAmount] => 4764.54 ) but when i call the array <table class="table table-striped"> <?php if(!empty(Session::get("cart_item"))) { foreach(Session::get("cart_item") as $row) { ?> <tr> <td width="70"><center><?php echo $row['ItemCode']; ?></center></td> <td><?php echo $row['ItemDesc']; ?></td> <td width="70"><center><?php echo $row['ItemQty']; ?></center></td> <td width="70"><center><?php echo $row['ItemAmount']; ?></center></td> <td width="70"><center><?php echo $row['ItemTotalAmount']; ?></center></td> </tr> <?php } } else { ?> <tr> <td colspan="5"><center><span class="rounded-pill p-1 px-5 bg-secondary">No Purchase Order Items Data Available!</span></center></td> </tr> <?php } ?> </table> I am getting the following error Error on Apr 22, 2024 22:25PM - Attempt to read property "ItemCode" Does anyone have any suggestions please I have also tried <tr> <td width="70"><center><?php echo $row->ItemCode; ?></center></td> <td><?php echo $row->ItemDesc; ?></td> <td width="70"><center><?php echo $row->ItemQty; ?></center></td> <td width="70"><center><?php echo $row->ItemAmount; ?></center></td> <td width="70"><center><?php echo $row->ItemTotalAmount; ?></center></td> </tr> But its throwing the exact same error
-
I have a materials table with over 7000 rows in it and it can take some time to load in datatables so have a pick from list drop down which works but not how i would like it, here is the code public function get_materials_pick($id) { return $this->db->select("SELECT ".PREFIX."tprices.IdPrice, ".PREFIX."tprices.Supplier, ".PREFIX."tprices.ProductCode, ".PREFIX."tprices.ProductDesc, ".PREFIX."tprices.Price FROM ".PREFIX."tprices WHERE ".PREFIX."tprices.ProductDesc LIKE '%$id%' ORDER BY ".PREFIX."tprices.Price, ".PREFIX."tprices.Supplier ASC"); } within datatables if i wanted to search say a black coat size XL i could put "Coat Black XL" "Black XL Coat" and anything and it would filter it but when I do the query above i have to type in the order its saved in the table Is their a way i can get arounf this Thanks in advance
-
That worked to a certain extend but if you want to write it is changing all occurrences of @name to the same value
-
I have a timeline element on a page which users can post comments on and tag other user. The issue i am having is when users are tagged by @name a select list pops up and you can select the user you want to tag, i wanted it similar to whatsapp but its all gone wrong. If i start typing then tag someone it returns @namenamename the more i type the longer the tag @namenamenamenamenamenamenamenamenamename and so on. Ideally when the user is selected i would like the word starting with the @character replacing I've tried searching for a solution but cant find anything Here is the script i have $(window).on('load',function(){ $('#notesbody').scrollTop($('#notesbody')[0].scrollHeight); }); $(document).on('keypress','#notes-input',function(e){ if(e.which==64){ $('#userlist').removeClass('d-none'); } }); $(document).on('click','#userlist', function(e){ const username = $(this).find('option:selected').val(); //username = $(this).val(); //$('#notes-input').val($('#notes-input').val() + username); $('#notes-input').val() = $('#notes-input').replaceWith('/@([a-z0-9_]+)/i', username); $('#userlist').addClass('d-none'); $('#notes-input').focus(); });