我正在开发一个插件。在激活挂钩上,我执行以下操作:
/* Create category */
global $wpdb;
$rpdb_category = $wpdb->prefix . "rp_category";
if($wpdb->get_var("show tables like \'$rpdb_category\'") != $rpdb_category) {
$create_table_query = "
CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}rp_category` (
`cid` BIGINT ( 20 ) NOT NULL AUTO_INCREMENT,
`cat` VARCHAR ( 110 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL ,
`catd` CHAR ( 1 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL ,
PRIMARY KEY ( `cid` )
) DEFAULT CHARSET=utf8mb4;
";
require_once( ABSPATH . \'wp-admin/includes/upgrade.php\' );
dbDelta( $create_table_query );
/* Insert values to category */
global $post;
$data = array(
\'cat\' => \'Uncategorized\',
\'catd\' => \'1\',
);
$format = array(
\'%s\'
);
$success = $wpdb->insert($rpdb_category, $data, $format);
}
我从rp\\U类别显示如下:
global $wpdb;
$rpdb = $wpdb->prefix . \'rp_category\';
$sql = "SELECT DISTINCT LEFT(cat, 1) as letter FROM $rpdb ORDER BY cat ASC";
$results = $wpdb->get_results($sql) or die(mysql_error());
foreach( $results as $result ) { ... }
我的问题是,当我从rp\\U类别显示时,foreach中没有输出任何内容。但是,如果我将id更改为“未分类”,或者添加一个id=0的新条目,那么一切都很好。因此,似乎rp\\U类别中的一个条目需要id为0才能正常工作。但是MySQL从1开始,而不是从0开始。我怎样才能解决这个问题?
善良的regardsJohan