I m using a quiz plugin which doesnt store the score in the database! I want to store the score for each quiz post for a login user... the variable use for the quiz result score is %%SCORE%% Also, is there any way to email the score to the login user.. can sombody help me in writing the code in correct way ,,,, mvery novice in php if (is_user_logged_in()) { add/insert the score %%SCORE%% in users database } else { $messagequiz = "u have to login to store ur score" }
no i dont ... u can download the plugin from here http://wordpress.org/extend/plugins/quizzin/ Will be very glad if u can sort out this issue ,,, Thanks in advance!
BrettOwnz is right -- you need at least the table info. Otherwise it's very straightforward -- get the quizz's value & push it into a table along with the quizz's identifier, adding some bells and whistles along the lines of a timestamp and the sort.
now i do i have a table info .. $sql = "CREATE TABLE {$wpdb->prefix}quiz_answer ( ID int(11) unsigned NOT NULL auto_increment, question_id int(11) unsigned NOT NULL, answer varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, correct enum('0','1') NOT NULL default '0', sort_order int(3) NOT NULL default 0, PRIMARY KEY (ID) ); CREATE TABLE {$wpdb->prefix}quiz_question ( ID int(11) unsigned NOT NULL auto_increment, quiz_id int(11) unsigned NOT NULL, question mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, sort_order int(3) NOT NULL default 0, explanation mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (ID), KEY quiz_id (quiz_id) ); CREATE TABLE {$wpdb->prefix}quiz_quiz ( ID int(11) unsigned NOT NULL auto_increment, name varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, description mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, final_screen mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, added_on datetime NOT NULL, PRIMARY KEY (ID) ); CREATE TABLE {$wpdb->prefix}quiz_users_scores ( quiz_id int(11) unsigned NOT NULL, user_id int(11) unsigned NOT NULL, percentage int(11) unsigned NOT NULL, grade int(11) unsigned NOT NULL, rating varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, played_on varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, user_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, user_email varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, quiz_name varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (quiz_id, user_id) );"; dbDelta($sql); update_option( "quizzin_db_version", $database_version ); } } // added register activation hook register_activation_hook(__FILE__,'quizzin_activate');
I believe a way to do it would be using the wordpress database connection and doing an INSERT MySQL query for the record. So it would be similar to: INSERT INTO `table_name` (`field`,`another_field`,`field3`) VALUES ('value1','value2','value3'); Then you would retrieve them by using the same method, but with a SELECT statement. If you would like further assistance, feel free to add me on MSN:
Firstly, that table structure is AWFUL; 'quiz_id' & 'user_id' should be fkeys to a quiz/users table.... and yet this table also stores user name, email, and quiz name..... redundant data. played_on, i assume is a timetamp... why is it a varchar? :/ Anyway, You can add the scores using the built in wordpress functions for it.... If you add something like the following, you then just need to pass in the details by calling the function once the user has completed the quiz; function add_quiz_user_scores($details) { global $wpdb; $wpdb->insert($wpdb->prefix . 'quiz_users_scores', array( 'quiz_id' => $details['quiz_id], 'user_id' => $details['user_id], 'percentage' => (from array?, or calculate this above), 'grade' => (as above), 'rating' => (as above), 'played_on' => (whatever this should be), 'user_name' => $details['user_name'], 'user_email' => $details['user_email'], 'quiz_name' => $details['quiz_name'] ) ); return $wpdb->insert_id; } PHP:
Ok luke ,,, can you do this for me... just have a look at the plugin ,... download it .. and play with it .. and let me know if u can do it ,,,, i hope ,, this wont be a hard job for a PHP expert guy .... Here is the download link for the plugin ... http://wordpress.org/extend/plugins/quizzin/ I will be very thankful to you ...If you can do this for me ! Let me know ur charges ,,, If applys...
Okey dokey - i have to pop out in a moment, but i'll take a look at this later tonight and get back to you - i'll send you a PM