我正在创建一个插件,但有一个问题。我试图循环访问数据库表并仅显示该列中的最后一个值。例如: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 |-----------------------------------------------------------------------------------------我需要的是仅显示最后一个值,例如Elementor值。这是我到目前为止所尝试过的:$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 } }}通过这种方式,我没有得到任何值,只有一个空字段。但是,一旦我$selectPluginSeconds以这种方式更改查询(使用静态值),我就只能得到该静态值:$selectPluginSeconds = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'wdl WHERE plugin_name="Elementor" ORDER BY id DESC LIMIT 1' );
1 回答
翻过高山走不出你
TA贡献1875条经验 获得超3个赞
连接有点混乱,这应该可以
$selectPluginSeconds = $wpdb->get_results(
"SELECT *
FROM {$wpdb->prefix}wdl
WHERE plugin_name='$queryPlugins'
ORDER BY id DESC
LIMIT 1" );
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消