Category: PHP

How to convert CTE to normal query?

Issue How can I convert this to normal query? WITH cte AS ( SELECT agentID, SUM(bonus > 0) OVER (PARTITION BY agentID ORDER BY `year` * 12 + `month` RANGE BETWEEN 2 PRECEDING AND CURRENT ROW) flag FROM test ) SELECT agentID FROM cte WHERE flag = 3; I need to convert this because I […]

Posted in PHP

Display WooCommerce related products based on specific product attribute value

Issue I am trying to get displayed related products based on specific product attribute “pa_kolekcja” term value (set on the product). I have a following piece of code (it’s almost ready): function woo_related_products_edit() { global $product; $current_kolekcja = “???”; // <== HERE $args = apply_filters( ‘woocommerce_related_products_args’, array( ‘post_type’ => ‘product’, ‘ignore_sticky_posts’ => 1, ‘no_found_rows’ => […]

Posted in PHP

Details of PHP 7.4 Reference Counting of Zvals

Issue I have some points of clarification based on reading the internal implementations for zvals described here Internal value representation in PHP 7 ‚Äì Part 1 and Internal value representation in PHP 7 ‚Äì Part 2. Before explaining my confusion in detail, I think it can be summed up by: (i) I do not see […]

Posted in PHP

get duration of audios in ffmpeg in php

Issue I am using PHP-FFMpeg library to work on audio and video files. I know that to get duration a specific video can like this : $ffprobe = \FFMpeg\FFProbe::create(); $duration = $ffprobe->format(‘path/to/file’)->get(‘duration’); But I know that how can I do that for a given audio file. Did anyone know a solution for that ? Solution […]

Posted in PHP

Get data from a form using post

Issue I have three dropdowns and I can’t get data from two of them using POST, here is my code: <form action=”{url module=ProductManagement action=downloadFilteredImages}” method=”post”> <table> <tbody> <tr> <td> <select class=”form-control selectpicker filter” name=”_id” multiple data-live-search=”true”> {foreach $suppliers as $supplier} <option value=”{$supplier.supplier_id}” {if $value eq $supplier.supplier_id}selected{/if}>{$supplier.supplier_name}</option> {/foreach} </select> </td> <td> <select class=”form-control selectpicker filter” name=”_id” […]

Posted in PHP

How to enable CORS in Laravel?

Issue I am in Laravel 5.8 ‚Äì I kept getting this CORS issue I’ve tried php artisan make:middleware Cors Add these code <?php namespace App\Http\Middleware; use Closure; class Cors { public function handle($request, Closure $next) { return $next($request) ->header(‘Access-Control-Allow-Origin’, ‘*’) ->header(‘Access-Control-Allow-Methods’, ‘GET, POST, PUT, DELETE, OPTIONS’) ->header(‘Access-Control-Allow-Headers’, ‘X-Requested-With, Content-Type, X-Token-Auth, Authorization’); } } restart my […]

Posted in PHP

Capture two numbers in a string with PHP preg_match

Issue Here is a very simple piece of code: <?php $matches = array(); $str = “You came in 21st out of 53”; preg_match(“/(\d+).*(\d+)/”,$str,$matches); echo var_dump($matches); ?> I am learning and experimenting with PHP’s preg_match and regular expressions. I thought the code above would capture ‚Äú21‚Äù and ‚Äú53‚Äù, but what it actually captures is ‚Äú21‚Äù and […]

Posted in PHP

Laravel : Combine two tables using Model relations

Issue i have two tables :: shops and attachments . Shops has all the details for shop and attachments with all the pictures for shop with ref_id as FK . now for mobile app i have to list shops with Shop title and one image. I can achieve it using leftjoin as below. Shop::select(‘shops.name as […]

Posted in PHP

array_search() with array_column() is very slow, how can I speed this up?

Issue Hi all I have the following function (With the internal stuff cut out) : /** * @param int $lastSyncTimeStampLocal * @return void */ protected function compareData(int $lastSyncTimeStampLocal): void { $time_start = microtime(true); foreach ($this->localData as $row) { $key = array_search($row[‘uuid’], array_column($this->masterData, ‘uuid’)); } $time_end = microtime(true); $execution_time = ($time_end – $time_start)/60; } This function […]

Posted in PHP