Options table for DB

<?php

//Setup DB
function lmcb_create_db_table(){
global $wpdb;
$lmcb_db_version = "1.0";

$table_name = $wpdb->prefix . "band_info";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
option_name VARCHAR(150) NOT NULL,
option_value TEXT NOT NULL,
UNIQUE KEY id (id)
);";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("lmcb_db_version", $lmcb_db_version);

//Band Options
$band_info_options = array('main_image','description');
foreach($band_info_options as $option){
$wpdb->insert($table_name, array('option_name' => $option, 'option_value' => ''));
}
}
}

add_action('init','lmcb_create_db_table');

function lmcb_to_band_info_db(){
global $wpdb;

$table_name = $wpdb->prefix . "band_info";
foreach($_POST as $key => $value){
$wpdb->update($table_name, array('option_value' => $value), array('option_name' => $key));
}
}

?>

0 Comments

You must be logged in to post a comment.