Is there any method to sort list in ascending order in php

$start = 0;
// Setting the number of rows to display in a page
$rows_per_page = 9;
$records = $mysqli->query("SELECT * FROM `indexjob`   ORDER BY `id` DESC");
$nr_of_rows = $records->num_rows;
// calculating of nr of pages
$pages = ceil($nr_of_rows / $rows_per_page);
// if the user clicks on the pagination buttons we set a new starting point.
if(isset($_GET['page-nr']))
{
    $page = $_GET['page-nr']-1;
    $start = $page * $rows_per_page;
}
$result = $mysqli->query("SELECT * FROM `indexjob`   ORDER BY `id` DESC LIMIT $start,$rows_per_page");

I am using Simple HTML DOM and PHP code to retrieve a list in ascending order on the webpage.

my code is working fine for the descending order but when I try to do it in ascending order it retrieves the same as in descending order.

I am trying to fix it by myself but I haven’t found a good solution

User Unsupported Data Source: https://officeltd.gmaltd.in/d.php is not a supported raster data source

The URL which I am providing downloading the .tif file but giving following error in QGIS : User Unsupported Data Source: https://officeltd.gmaltd.in/d.php is not a supported raster data source.

The contents of d.php file is :

[‘verify_peer’ => false, ‘verify_peer_name’ => false]]);
readfile($rasterPath, false, $context);
} else {

header(‘HTTP/1.1 404 Not Found’);
echo ‘File not found.’;
}
?>

I want to roster .tif file in QGIS Application by providing the URL : https://officeltd.gmaltd.in/d.php

If I am providing this url : “https://10.14.52.16/Careers/25143_LOGOWER_LKGMB_LMN.tif” in QGIS then it rosters the image correctly.

how to print Open layer map in pdf

I have added open layer map with multiple layers and multiple shapes in php.
While exporting to PDF mutltiple layers are exporting with their specific button.
I am attaching screenshot for reference how it is printing in php page.

As shown in image same thing required in pdf 1

In pdf it is printing only 1 layer

Login to multiple php accounts with same credentials

I’m trying to launch multiple sites with different functionalities but my market is the same, so I would like for a client to register in one site but use the same credentials to login to another. All sites are in php. Something like “Login with Facebook” but instead of Facebook it says my main site. How can I do this?

I’ve been researching the REST API but I can’t find conclusive answers if this would work

Get access to roundcube only for authenticated users

I’m trying to add roundcube to my laravel website : below folder’s structure

public_html

  • app
  • public
  • resources
  • roundcube
    now the problem is : i want that only user logged in my website can access to roundcube cause now if i type mywebsite.com/roundcube i can access to it even if i’m not authenticated.
    Also i would like to autocomplete email field with session user’s email.
    Can someone help me? Thanks

For autocomplete email i’ve tried to access session variable, but this does not have effect

Wait for the response from a PHP page before submitting a form

Before submitting a form, I want to validate the data by calling a PHP page, which returns an empty string if everything is okay and an error message if not. My current code works, but async: false is deprecated. I’m having trouble finding an alternative that works. Can you help me?

Thank you!

$("form").on("submit", function(event) {
    let idForm = $(this).attr("id");
    if(correspFormCtrl[idForm]) {
        let dataFormArray = $(this).serializeArray();
        let dataForm = dataFormArray.reduce((acc, item) => {
            acc[item.name] = item.value;
            return acc;
        }, {});
        let cible = $(this);
        let ok = false;
        
        
        
        $.ajax({
            url : "php/verifHtmlForm.php", 
            type: "POST",
            async: false,
            data: { listeChamps: correspFormCtrl[idForm].champs, valeursForm: dataForm},
            success: function(data) {
                if(data) {
                    cible.find(".retourErreurForm").removeClass("invisible")[0].scrollIntoView({ block: 'start' });
                    cible.find(".infosErreurHtml").html(data);
                }
                else {
                    cible.find(".retourErreurForm").addClass("invisible");
                    ok = true;
                }
            },
            complete : function() {
                if(!ok) {
                    event.preventDefault();
                    return false;
                }
            },
            error: function(error) {
                console.error(error);
            }
        });
    }
});

I try Promise, but don’t know exactly how to use or if it’s appropriate.

How to convert Gemini pro API’s response text into html code

How can I integrate the Gemini Pro API into my PHP website and effectively convert the received response text into HTML code?

I’m seeking guidance on the process of transforming the API response text into a format compatible with HTML, and I would appreciate any insights or instructions from those experienced with this particular task.

MySQL – Fetching From 100 Tables With Good Performance

The Problem

To set the scene, I work on a PHP Laravel system that has taken a drupal-style approach where every field is its own MySQL table. Every table has optimum indexing making it very quick to fetch data for a specific record on a table-by-table basis. Each field table could contain 1, or multiple values.

Example Table Layout

To fetch a record, our system procedurally iterates the fields on a given record and runs one query per field to fetch the data. Each query is lightning-fast and returns values. In the example above, this means 4 queries get run to fetch the field data.

The problem is that some record types might have 100+ fields attached resulting in 100+ queries being run. This works, but the timing can add up to 0.2+ seconds or so to fetch everything.

Not a major issue, but I’ve been pondering if there’s a better way. It feels like it should be possible to fetch this all with a single faster query.


Tried Solutions

Attempt #1: I’ve tried using UNION to pass all queries in one go (with some clever logic to standardise select across the board). This returns the right results but seems to take much longer than 100 independent indexed queries.

Attempt #2: I’ve tried left joins from the record table (and splitting them into batches of 50 fields to avoid the MySQL 61 join limit). While this achieves the speeds I’m looking for, there’s an awful lot of data duplication where the joined field tables have multiple values. This requires some sorting PHP-side and feels somewhat fragile.


Summary

I’ve provided the above for context. In simple terms, this comes down to:

Imagine:

  • Field 1 table has 1 value
  • Field 2 table has 10 values
  • Field 3 table has 4 values
  • Field 4 table has 80 values

Due to the way left joins behave, I end up with 1 * 10 * 4 * 80 rows (3200 rows) in the MySQL response which I have to sift through in PHP to understand the “real” values (95 rows).

Is there a single query I can run just retrieve the 95 table rows I want directly? Either through joins or some other means?

Performance is key. I’m looking for the most efficient approach.


Examples

Here’s an example of a field table with some test data. In this example, there’s some peripheral data about the record it belongs to and when it was created. I need the opex_id, currency_code, forecast, value and comment columns that make up this field payload.

Field Table Example

Imagine the other 3 fields in the example are similar. but with their own column names.

How can I handle my messages with RabbitMQ and Symfony Messenger

I have 3 Symfony projets. All are using the same user entity but have 3 different databases (1 per project).
I want to replicate data when one of the project is editing / creating / deleting a user.

So I have a message broker (RabbitMQ).

The desired behavior I want to have is this:

  • When project 1 is sending a message, project 2 and 3 reads it, but 1 not
  • When project 2 is sending a message, project 1 and 3 reads it, but 2 not
  • When project 3 is sending a message, project 1 and 2 reads it, but 3 not

But actually, when I’m sending a message (from 1 or 2 or 3), the project itself also reads the message…

This is my configuration:

framework:
    messenger:
        # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
        # failure_transport: failed
        serializer:
            default_serializer: messenger.transport.symfony_serializer
            symfony_serializer:
                format: json
                context: { }

        transports:
            sso:
                dsn: '%env(TRANSPORT)%/sso'
                serializer: messenger.transport.symfony_serializer
                options:
                    exchange:
                        name: my_fanout
                    queues:
                        queue1: ~

        routing:
            # Route your messages to the transports
             'AcmeCoreBundleMessageCreatedCreatedUserNotification': sso

What I missed? Does anyone have an idea?

Add Bootstrap css, Bootstrap js, jQuery, jQuery form to wordpress theme or plugin

function load_css_js(){

    wp_enqueue_style( 'AJDWP_bootstrap_css', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css' );    
    wp_enqueue_script( 'AJDWP_bootstrap_js', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js' );    
    wp_enqueue_script( 'jquery');
    wp_enqueue_script('jquery-form');
    wp_enqueue_script( 'AJDWP_jquery-3.6.0', 'https://code.jquery.com/jquery-3.6.0.min.js' );
    wp_enqueue_script( 'AJDWP_bootstrap-js-4.3.1', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js' );
    wp_enqueue_script( 'AJDWP_bootstrap-bundle-4.3.1', 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js' );
    
}
add_action( 'wp_enqueue_scripts', 'load_css_js' );

It is Working Properly 🙂

How to automatically logout user from Guacamole after date expiration?

I developped an application in php to interagit with my guacamol with curl, in order to configure the date of acess and expiration.
I succeded ! But I noticed that once the date expired, the user remains logged in …

I thought of 2 solutions :
Maybe I forgot a setting to automatically log out users with an expired date.
Or I want request to know the token of users connected and kick him with other request.
DELETE http://server/guacamole/api/session/”token”

I have try to delete token of users and it work but I don’t know how I can get token of user with a request.

I’m Greatful for any help

How to generate all the permutations of 2 letters and 2 numbers in PHP

So, I have been trying to adapt all the examples I have found but haven’t quite found the solution.
What I would like to end up with is a list off all the permutations of a combination of letters and numbers but the output is always has 2 letters and 2 numbers (in all orders).

What I have so far is:

function combinations($arrays, $i = 0) {
    if (!isset($arrays[$i])) {
        return array();
    }
    if ($i == count($arrays) - 1) {
        return $arrays[$i];
    }

    // get combinations from subsequent arrays
    $tmp = combinations($arrays, $i + 1);

    $result = array();

    // concat each array from tmp with each element from $arrays[$i]
    foreach ($arrays[$i] as $v) {
        foreach ($tmp as $t) {
            $result[] = is_array($t) ? 
                array_merge(array($v), $t) :
                array($v, $t);
        }
    }
    return $result;
}

$letters = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$numbers = array("0","1","2","3","4","5","6","7","8","9");

$combinations = combinations(array( $letters, $letters, $numbers, $numbers));

foreach ($combinations as $values) {
    echo implode("",$values).'<br>';
}

But that only outputs results in the order of 2 letters first followed by the two numbers.

Also bonus question, how do I calculate the total results I should be expecting, I know if it was all letters, it would be 26x26x26x26 so 4 letters only I would be expecting 456,976, but what about 2 letters & 2 numbers?

PHP prevent calling all function in a class when a condition is not met

Suppose i have two classes and i need to call one method from another class if there is a speciific condition is met(i.e: If a gateway is active)

Suppose i have Stripe class and a method in it called createProduct(). I have another class Payment and i want to call that method (createProduct()) from Payment class and there will be no error.

<?php
   class Stripe(){
        public function __construct(){
             if( !$active_stripe ) return;
        }
        public function createproduct(){
             //... Stuffs to create a product
        }
   }     


<?php
   class Payment(){
        public $stripe;
        public function __construct(){
             $this->stripe = new Stripe();
        }
        public function fnCreateproduct(){
             $prod = $this->stripe->createProduct();
        }
   }   

Though i am checking is stripe active in __construct fn in first class the createproduct() is still being called.