Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Proper way for WHERE clause with PHP and MySQL

I'm creating a plugin, and I have one problem.

I'm trying to loop through the database table and to show only the last values from the column.

For example:

id | plugin_name                    | plugin_path                   | plugin_time_delay |
-----------------------------------------------------------------------------------------
1  | Elementor                      | elementor/elementor.php       | 5                 |
-----------------------------------------------------------------------------------------
2  | Health Check & Troubleshooting | health-check/health-check.php | 3                 |
-----------------------------------------------------------------------------------------
3  | Elementor                      | elementor/elementor.php       | 7                 |
-----------------------------------------------------------------------------------------

What I need is to show only the last value for example for Elementor value.

This is what I have tried so far:

$all_plugins = get_plugins();

foreach ( $allPlugins as $key => $allPlugin ) {
    $queryPlugins = $allPlugin['Name'];

    $selectPluginSeconds = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'wdl WHERE plugin_name=".$queryPlugins." ORDER BY id DESC LIMIT 1' );

    foreach ( $selectPluginSeconds as $select_plugin_second ) {
        if ($allPlugin['Name'] == $select_plugin_second->plugin_name) { ?>
            <input type="text" style="width: 200px" value="<?= $select_plugin_second->plugin_time_delay . __( ' seconds.', 'wdl') ?>" disabled>
        <?php }
    }
}

In this way I don't get any values, ( see the image ) only an empty field. But as soon as I change $selectPluginSeconds query on this way ( with static value ) then I get only that static value ( see the image ) :

$selectPluginSeconds = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'wdl WHERE plugin_name="Elementor" ORDER BY id DESC LIMIT 1' );
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The concatenation was a little mixed up, this should work

$selectPluginSeconds = $wpdb->get_results( 
        "SELECT * 
        FROM {$wpdb->prefix}wdl 
        WHERE plugin_name='$queryPlugins' 
        ORDER BY id DESC 
        LIMIT 1" );
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda