www.webdeveloper.com
Results 1 to 3 of 3

Thread: Table data into a form

  1. #1
    Join Date
    May 2010
    Posts
    2

    Table data into a form

    I've hit a wall with my script any help / ideas would be really appreciated.

    I've written some reporting which fetches data from three mysql tables, applies some php logic then populates a table in a page with (amongst other fields) a medal (Gold, Silver, Bronze). There needs to be some manual moderation by visitor at this point. A visitor should be able to override the automatically calculated medal if they don't agree with it. Hopefully the screen shot attached makes sense.

    I then want the overriden medal be updated in the original database table.

    I'm stuck on how I process all the medals (including moderated ones) in one go.

    Hope this makes sense

    Screenshot:
    http://citybit.southampton-city.ac.uk/gsb_table.png

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    I think you would have a better chance of getting some help if you posted your code.

  3. #3
    Join Date
    May 2010
    Posts
    2

    My code

    That's a good shout, thanks Here's my code:

    PHP Code:
    <?php 

     
    //connect to server
     
    $con mysql_connect("localhost","username","password");
        if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
      
        
    //connect to db
        
    mysql_select_db("citybit0809"$con);
      
        
    $categoryid $_POST['dept'];
        
        
    //echo $categoryid;
      
        //get course category name
        
    $get_dept_name mysql_query("SELECT name FROM mdl_course_categories where id = $categoryid");
        
    $dept_name mysql_fetch_assoc($get_dept_name);
        echo 
    $dept_name['name'];
        
        
    $dept_name_text $dept_name['name'];
        
        echo 
    "<br /><br />";
        
        echo 
    "<form method='post' action='http://musca/process.php' name='gsb_process_form'><br><br><input type='submit' name='submit' value='Process GSB Medals'></font></p><br>";
        
        echo
    "
            <table border='1' cellspacing='0' cellpadding='2' width='100%'>
            <tr>
                <td bgcolor='#C0C0C0'><b>ID</b></td>
                <td bgcolor='#C0C0C0'><b>Shortname</b></td>
                <td bgcolor='#C0C0C0'><b>Course name (click name to visit course)</b></td>
                <td bgcolor='#C0C0C0'><b>More course info</b></td>
                <td bgcolor='#C0C0C0'><b>NEW GSB SCORE</b></td>
                <td bgcolor='#C0C0C0'><b>Previous GSB Score</b></td>
                <td bgcolor='#C0C0C0'><b>Override GSB</b></td>
            </tr>"
    ;
        
        
        
    //get course codes from department
        
    $get_dept_codes mysql_query("SELECT id, shortname, gsb, fullname FROM mdl_course where category = $categoryid order by id asc");

        
    //loop through and process gsb stats for courses 
        
    while($row mysql_fetch_array($get_dept_codes))
            {
                 
    $courseid $row['id'];
                
    $courseshortname $row['shortname'];
                
    $coursefullname $row['fullname'];
                
    $old_gsb_score $row['gsb'];
                
                if (
    $old_gsb_score == ""$old_gsb_score "&nbsp;";
                else 
    $old_gsb_score $old_gsb_score;
                
                
    //bronze stats
                
    $standardslinknum mysql_query("update coursestandards set coursestandards.linksnum = (SELECT count(*) FROM mdl_resource where type<>'ims' and course=$courseid) where coursestandards.courseid=$courseid");

                
    //silver stats
                
    $standardsassnum mysql_query("update coursestandards set coursestandards.assignmentnum = (SELECT count(*) FROM mdl_assignment where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsfeedbacknum mysql_query("update coursestandards set coursestandards.feedbacknum = (SELECT count(*) FROM mdl_feedback where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsimailnum mysql_query("update coursestandards set coursestandards.imailnum = (SELECT count(*) FROM mdl_mail where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsfeedbacknum mysql_query("update coursestandards set coursestandards.feedbacknum = (SELECT count(*) FROM mdl_feedback where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsinteractnum mysql_query("update coursestandards set coursestandards.interactnum = (SELECT count(*) FROM mdl_resource where type='ims' and course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsquestnum mysql_query("update coursestandards set coursestandards.questnum = (SELECT count(*) FROM mdl_questionnaire where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsquiznum mysql_query("update coursestandards set coursestandards.quiznum = (SELECT count(*) FROM mdl_quiz where course=$courseid) where coursestandards.courseid=$courseid");    
        
                
    //gold stats
                
    $standardschatnum mysql_query("update coursestandards set coursestandards.chatnum = (SELECT count(*) FROM mdl_chat where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardsforumbacknum mysql_query("update coursestandards set coursestandards.forumnum = (SELECT count(*) FROM mdl_forum where course=$courseid) where coursestandards.courseid=$courseid");
                
    $standardswikinum mysql_query("update coursestandards set coursestandards.wikinum = (SELECT count(*) FROM mdl_wiki where course=$courseid) where coursestandards.courseid=$courseid");    
            
                
    //Gold, Silver, Bronze logic
                
    $bronze_score mysql_query("select coursestandards.linksnum from coursestandards where coursestandards.courseid = $courseid");

                
    $bs mysql_fetch_assoc$bronze_score );

                
    $bss $bs['linksnum'];
                
                if (
    $bss 30$gsb_score "In Dev";

                else 
                
                    { 

                    
    $gsb_bronze 1;

                    
    $silver_fetch mysql_query("select coursestandards.assignmentnum, coursestandards.interactnum, coursestandards.feedbacknum, coursestandards.questnum, coursestandards.quiznum from coursestandards where courseid = $courseid");

                    
    $silver_array mysql_fetch_assoc$silver_fetch );

                    
    $silver_counter 0;

                    if (
    $silver_array['assignmentnum'] > 0$silver_counter ++;
                    if (
    $silver_array['interactnum'] > 0$silver_counter ++;
                    if (
    $silver_array['feedbacknum'] > 0$silver_counter ++;
                    if (
    $silver_array['questnum'] > 0$silver_counter ++;
                    if (
    $silver_array['quiznum'] > 0$silver_counter ++;
                    if (
    $silver_counter 1$gsb_silver 10;
                    else 
    $gsb_silver 0;

                    
    $gold_fetch mysql_query("select coursestandards.forumnum, coursestandards.chatnum, coursestandards.wikinum, coursestandards.imailnum from coursestandards where courseid = $courseid");

                    
    $gold_array mysql_fetch_assoc$gold_fetch );

                    
    $gold_counter 0;

                    if (
    $gold_array['forumnum'] > 0$gold_counter ++;
                    if (
    $gold_array['chatnum'] > 0$gold_counter ++;
                    if (
    $gold_array['wikinum'] > 0$gold_counter ++;
                    if (
    $gold_array['imailnum'] > 0$gold_counter ++;

                    if (
    $gold_counter 1$gsb_gold 100;
                    else 
    $gsb_gold 0;

                    
    $gsb $gsb_bronze $gsb_silver $gsb_gold;

                    if (
    $gsb == 111$gsb_score "Gold";
                    else if (
    $gsb == 11$gsb_score "Silver";
                    else if (
    $gsb == 1$gsb_score "Bronze";
                    else if (
    $gsb == 101$gsb_score "Bronze";
                    else 
    $gsb_score "In Dev";
                    
                                                    
                    }
                    
                
                    echo   
    "<tr>
                            <td>
    $courseid</td>
                            <td>
    $courseshortname</td>
                            <td><a target='_blank' title='Click to enter this course' href='http://musca/citybit2/course/view.php?id=
    $courseid'>$coursefullname</a></td>
                            <td><a target='_blank' title='More course info' href='http://musca/stats/courseinfo/course_info.php'>More course info</a></td>
                            <td>
    $gsb_score</td>
                            <td>
    $old_gsb_score</td>
                            <td>
                            <p align='right'><select size='1' name='override_gsb'>
                            <option></option>
                            <option value='Gold'>Gold</option>
                            <option value='Silver'>Silver</option>
                            <option value='Bronze'>Bronze</option>
                            <option value='In Dev'>In Dev</option>
                            <option value='exclude'>Exclude</option>
                            </select></td>
                            </tr>
                            
                    <input type='hidden' name='prevgsb' value=
    $old_gsb_score>
                    <input type='hidden' name='currentgsb' value=
    $gsb_score>
                    <input type='hidden' name='courseid' value=
    $courseid>";
                            
                    
                                            
            }
            
            
            echo 
    "<input type='hidden' name='course' value=$dept_name_text>
                </form>"
    ;

    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12532 seconds
  • Memory Usage 2,974KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates