I use below code create and insert record in my table in wordpress database
global $jal_db_version;
$jal_db_version = "1.0";
function jal_install() {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . "anncurtis";
$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
Ability VARCHAR(25) NOT NULL,
Session VARCHAR(60) NOT NULL,
Time VARCHAR(50) NOT NULL,
Itemname VARCHAR(90) NOT NULL,
Itemid int(8) NOT NULL,
Childname VARCHAR(50) NOT NULL,
UNIQUE KEY id (id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("jal_db_version", $jal_db_version);
}
function jal_install_data($ablty,$sesion,$tiime,$itm_name,$itm_id,$chld_name) {
global $wpdb;
$table_name = $wpdb->prefix . "anncurtis";
$rows_affected = $wpdb->insert( $table_name, array( 'Ability' => $ablty, 'Session' => $sesion, 'Time' => $tiime,'Itemname' => $itm_name,'Itemid' => $itm_id,'Childname' => $chld_name ) );
}
Now i used below code for to fetch the records,
$table_name = $wpdb->prefix . "anncurtis";
$fivesdrafts = $wpdb->get_results(
"SELECT * FROM $wpdb->$table_name"
);
foreach ( $fivesdrafts as $fivesdraft )
{
echo $fivesdraft->Ability;
}
But i can't fetch the records. what is the problem?.
How can i fetch the records from my own table which is created in wordpress database.?
print_r( $fivesdraft ), also, are you sure your records are making it into your database? Use a tool like phpMyAdmin to verify the data is there and that the table exists, etc. – m0r7if3r Jan 31 at 12:45