Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda