SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: $_get

  1. #1
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy $_get

    I have a variable on page 1, $page. On page 2 I want to read that $page.

    I have tried $HTTP_GET_VARS[$page]; and $_GET[$page]; but neither bring in a result. Do I need to do something to $page first so I can transfer it?

    Thanks

  2. #2
    SitePoint Zealot shenkong's Avatar
    Join Date
    Sep 2004
    Location
    China
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your url must like this "http://www.abc.com/index.php?page=1"
    then you do this in "index.php":
    PHP Code:
    echo $_GET["page"];//print "1" 
    the query string is page=1
    and page is one of the $_GET array keys

  3. #3
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's not in a url though... it was originally. on quiz.php i have ...page=1 page=2 etc so i use

    if(isset($HTTP_GET_VARS['page']))
    {
    $page = intval($HTTP_GET_VARS['page']);
    }

    to get that one, this is on testviewq.php
    on quizzer.php i need to get $page, because that has the number required to get info from the database.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    How do you go from one page to another?

    If it is an include/require, then there is no need for $_GET. The variable should already be known and have it's value.

    If it is through a link the user has to click, then you must put the variable in the url as explained by shenkong.

  5. #5
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.cricketmx.com/testforum/t...php?viewquiz=1

    Clicking submit will take you to quizzer.php

    i have tried include but I get a page full of errors

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    thepigeon is always on the move...
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you been able to access any other variables from your form? Can you show us your code?
    peck! peck! go to heck...
    thepigeon

  7. #7
    SitePoint Zealot shenkong's Avatar
    Join Date
    Sep 2004
    Location
    China
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use $_POST when you submit a form, use $_GET to get the URL queries

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If $page ain't a field of the form, you might add it as a hidden field.

    Adding the hidden field, since you're using the method "post", you must use $_POST instead of $_GET on the receiving page.

  9. #9
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    define('IN_PHPBB'true);
    define('SHOW_ONLINE'true);
    $phpbb_root_path './';
    include(
    $phpbb_root_path 'extension.inc');
    include(
    $phpbb_root_path 'config.'.$phpEx);
    include(
    $phpbb_root_path '/includes/constants.'.$phpEx);
    include(
    $phpbb_root_path 'common.'.$phpEx);

    $numer $board_config['questions_quiz'] + 1;

    $contents=""
    for (
    $xx=0$xx $numer$xx++) 
    $user_answer $user_answer "" $_POST[$xx]; 

    if(!
    $user_answer)
    {
    message_die(GENERAL_ERROR'Please fill in all answers!');
    }

    $matchw $user_answer;

    // Match user answer with real answer
    $smatch "SELECT * 
            FROM phpbbtestboard_quiz_text
            WHERE game_id = 1"
    ;
            
    $yups mysql_query($smatch);
     
    $ans '';
    while(
    $row mysql_fetch_array($yups))
    {
        
    $ans .= $row['answer'];
     
        
    $t3 $ans;
        
    $t1 $matchw;

    $check_for_match1 strcmp($t1$t3); // returns 0, and therefore matches
    //$check_for_match2 = strcmp($var1, $var3); // doesn't return 1, and therefore doesn't match

    if ($check_for_match1 == 0)
    {
    //
       
    message_die(GENERAL_MESSAGE'Congratulations, you have scored 100%!');
    }
    if (
    $check_for_match1 == -1)
    {
       
    message_die(GENERAL_MESSAGE'You have incorrect answers! Better luck next time!');
    }

    That's quizzer.php the file I want to echo the $page in.

    PHP Code:
    define('IN_PHPBB'true); 
    $phpbb_root_path './'
    include(
    $phpbb_root_path 'extension.inc'); 
    include(
    $phpbb_root_path 'common.'.$phpEx);

    $page_title $lang['Quiz_page']; 
    //include($phpbb_root_path . 'includes/page_header.'.$phpEx); 

    // 
    // Start session management 
    // 
    $userdata session_pagestart($user_ipPAGE_PROFILE); 
    init_userprefs($userdata); 
    // 
    // End session management 
    // 

    include($phpbb_root_path 'includes/page_header.'.$phpEx);

    if(isset(
    $HTTP_GET_VARS['viewquiz'])) 

       
    $page intval($HTTP_GET_VARS['viewquiz']); 



    // What's THIS one called?
    // You'd like to know wouldn't ya

    if(isset($page)) 

    $title "SELECT quiz_name 
                 FROM " 
    QUIZ_TABLE 
                 WHERE quiz_id = 
    $page";
                 
    if ( !
    $result $db->sql_query($title) )
    {
       
    message_die(GENERAL_ERROR'Cannot find quiz name'''__LINE____FILE__$title);
    }
        
    while (
    $row mysql_fetch_assoc($result))
    {
    $quiz_title $row['quiz_name'];
    $quiz_title_disp "<a href='./viewquestions.$phpEx?viewquiz=$page'>$quiz_title</a><br>";



       
    $sql "SELECT * FROM phpbbtestboard_quiz_text 
                   WHERE game_id = 
    $page 
                   LIMIT " 
    $board_config['questions_quiz'] . ""
       
    $result $db->sql_query($sql); 
       while (
    $row mysql_fetch_assoc($result)) 
       {
         
    $q $row['question']; 
         
         
    $f1 $row['fake1'];  
         
    $f2 $row['fake2']; 
         
    $f3 $row['fake3']; 
         
    $a $row['answer']; 
         
    $inp $row['quiz_id'];
         
         {
         
    $template->assign_block_vars('quizrow', array(
          
    'ACTQ' => $q,
          
    'ACTA' => $a,
          
    'FO' =>$f1,
          
    'FT' => $f2,
          
    'FTH' => $f3,
          
    'INPUT' => $inp)
          );
       }
       }
      }
     
    else 

       print 
    "No quiz has been specified"
    }
     
     
    $template->assign_vars(array(
          
    'QUESTION' => $lang['Question'],
          
    'ANSWER' => $lang['Answer'],
          
    'QUIZ_HEADER' => $quiz_title_disp)
    );

    // So sad, St Kilda lost :'(
    // Hope my coding stays quality :P
       
       
    $template->set_filenames(array('body' => 'viewquiz_body.tpl'));
       
    //
    // Generate the page
    //
    $template->pparse('body');

    include(
    $phpbb_root_path 'includes/page_tail.'.$phpEx); 
    testviewq.php
    The page where $page lies.

    PHP Code:
    define('IN_PHPBB'true);
    define('SHOW_ONLINE'true);
    $phpbb_root_path './';
    include(
    $phpbb_root_path 'extension.inc');
    include(
    $phpbb_root_path 'common.'.$phpEx);
    include(
    $phpbb_root_path 'config.'.$phpEx);
    include(
    $phpbb_root_path '/includes/constants.'.$phpEx);

    $userdata session_pagestart($user_ipPAGE_PROFILE);
    init_userprefs($userdata);

    $template->set_filenames(array('body' => 'quiz_body.tpl'));
    $page_title $lang['Quiz_page']; 
    include(
    $phpbb_root_path 'includes/page_header.'.$phpEx);

    // Time to get the authors :D

    $aut "SELECT q.*, u.* 
                 FROM " 
    QUIZ_TABLE " AS q, " USERS_TABLE " AS u
                 WHERE q.quiz_author = u.user_id"
    ;
                 
    if ( !
    $result $db->sql_query($aut) )
    {
       
    message_die(GENERAL_ERROR'No author data found'''__LINE____FILE__$aut);
    }
        
    while (
    $row mysql_fetch_assoc($result))
    {
    $quiz_aut $row['username'];
    $quiz_userid $row['user_id'];
    $quizauto "<a href='./profile.php?mode=viewprofile&u=$quiz_userid'>$quiz_aut</a>";

    $qn "SELECT quiz_id 
                        FROM " 
    QUIZ_TABLE 
                        ORDER BY quiz_id DESC
                        LIMIT 1"
    ;

    // ok, we're getting the total quiz # now...
    // i'm so excited, i cant believe the index is nearly done.. =P
    if ( !$result $db->sql_query($qn) )
    {
       
    message_die(GENERAL_ERROR'No quizzes found!'''__LINE____FILE__$sql);
    }

            while( 
    $row $db->sql_fetchrow($result))
    {
    $quiz_number_id $row['quiz_id'];
    }

    $sql "select * from " QUIZ_TABLE " WHERE quiz_enabled = '1'";
    $query $db->sql_query($sql
    or die(
    "error"); 

    while (
    $row mysql_fetch_assoc($query)){
    $quiz_id $row['quiz_id'];
    $quiz_name $row['quiz_name'];
    $quizo "<a href='./testviewq.php?viewquiz=$quiz_id'>$quiz_name</a>";

    $template->assign_vars(array(
          
    'QUIZZIE' => $lang['Quizzie'],
          
    'QUIZZIO' => $lang['Quizzio'],
          
    'QUIZ_NUMBER' => sprintf($lang['Quiz_number'], $quiz_number_id))
    );

      
    $template->assign_block_vars('quizrow', array(
          
    'QUIZ_TITLE' => $quizo,
          
    'QUIZ_CREATOR' => $quizauto)
      );
       }
       }
    //
    // Generate the page
    //
    $template->pparse('body');

    include(
    $phpbb_root_path 'includes/page_tail.'.$phpEx); 
    quiz.php, where all the fun starts. lol


Bookmarks

Posting Permissions

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