php help wordpress

Discussion in 'PHP' started by mike4uuu, Jul 30, 2010.

  1. #1
    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"

    }
     
    mike4uuu, Jul 30, 2010 IP
  2. BrettOwnz

    BrettOwnz Member

    Messages:
    286
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #2
    Do you already have a table in the database to store the scores? If so, whats the name of it?

    -Brett
     
    BrettOwnz, Jul 30, 2010 IP
  3. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    mike4uuu, Jul 30, 2010 IP
  4. bigmax

    bigmax Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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.
     
    bigmax, Jul 30, 2010 IP
  5. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #5
    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');
     
    mike4uuu, Jul 30, 2010 IP
  6. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #6
    now how do i insert the score,quiz and user details
     
    mike4uuu, Jul 30, 2010 IP
  7. seomadhur

    seomadhur Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #7
    The high scores is not available in the current version - maybe in a future version.
     
    seomadhur, Jul 31, 2010 IP
  8. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #8
    I'm willing to pay a small amount to whomsoever who can do this for me ,,,,
     
    mike4uuu, Jul 31, 2010 IP
  9. ze0xify

    ze0xify Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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:
     
    ze0xify, Jul 31, 2010 IP
  10. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #10
    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:
     
    lukeg32, Jul 31, 2010 IP
  11. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #11
    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...
     
    mike4uuu, Jul 31, 2010 IP
  12. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #12
    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
     
    lukeg32, Jul 31, 2010 IP
  13. mike4uuu

    mike4uuu Active Member

    Messages:
    832
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #13
    Thanks Buddy ... feel good to know that " There Are Still Good Peoples in This World "
     
    mike4uuu, Jul 31, 2010 IP