Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8943157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:42:17+00:00 2026-06-15T11:42:17+00:00

Im new to php functions and I am currently trying to construct an if

  • 0

Im new to php functions and I am currently trying to construct an if statement that looks into a database table to look at a column called tableformatting. This table is where the formatting options for my quiz questions are stored, e.g if I want the answers to my question displayed as a dropdown menu I would select that option when adding the quiz question, and then when it is pulled out of the database it will be formatted like that.

At present the if statement looks like this :

    <?php
    // Lookup Question Format & Format Using Function //
    $questionformat="SELECT * FROM itsnb_chronoforms_data_createquestions WHERE questionID='$questionID'";
    $questionformatresult =mysql_query($questionformat);
    while ($formatrow = mysql_fetch_array($questionformatresult)){
    $format = $formatrow['questionformat']; }

            if ($format == 'questionformatdropmenu')
            {dropdownmenu ();
            }
            else
            {}

     ?> 

and the formatting functions look like this :

<?php
    // Question formatting functions //

    // Dropdown Menu
    function dropdownmenu(){

    echo '<select id="quizselectanswer" name="quizselectanswer" title="quizselectanswer">';

    $sql="SELECT * FROM itsnb_chronoforms_data_createquestions WHERE questionID='$questionID'";
    $result2 =mysql_query($sql);
    while ($data = mysql_fetch_array($result2)){

      echo '<option value ="' . $data['quizanswer1'] . '" >' . $data['quizanswer1'] . '</option>';
      echo '<option value ="' . $data['quizanswer2'] . '" >' . $data['quizanswer2'] . '</option>';
      echo '<option value ="' . $data['quizanswer3'] . '" >' . $data['quizanswer3'] . '</option>';
      echo '<option value ="' . $data['quizanswer4'] . '" >' . $data['quizanswer4'] . '</option>';
        }
      echo '</select>';
      }
    // Question formatting functions END //
    ?>

The problem I am having is the function is creating the dropdown list menu just fine, but the data isnt being filled in for some reason and the dropdown menu is just blank, if I take the code out of the function and run it normally though it all works as expected and the menu is populated with the answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:42:19+00:00Added an answer on June 15, 2026 at 11:42 am

    You’re trying to access the $questionID variable out of scope. Try passing it to the function, eg:

    // Dropdown Menu
    function dropdownmenu ( $questionID ) {
      echo '<select id="quizselectanswer" name="quizselectanswer" title="quizselectanswer">';
    
      $sql="SELECT * FROM itsnb_chronoforms_data_createquestions WHERE questionID='$questionID'";
      $result2 =mysql_query($sql);
    
      while ( $data = mysql_fetch_array( $result2 ) ) {
        echo '<option value ="' . $data['quizanswer1'] . '" >' . $data['quizanswer1'] . '</option>';
        echo '<option value ="' . $data['quizanswer2'] . '" >' . $data['quizanswer2'] . '</option>';
        echo '<option value ="' . $data['quizanswer3'] . '" >' . $data['quizanswer3'] . '</option>';
        echo '<option value ="' . $data['quizanswer4'] . '" >' . $data['quizanswer4'] . '</option>';
      }
    
      echo '</select>';
    }
    

    Then call the function from your first loop like so:

    dropdownmenu($questionID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need help in debugging my code. Im new into php and im currently
Ok I am learning php and trying out classes and functions. Currently I have
I am new to php and trying to write a login function. Bit stuck
I am trying to use a PHP form (new.php) to update 2 MySQL tables
I'm currently trying to create a PHP Thrift server which will be accessed by
I've been trying my hand at OO PHP, and currently have three files. I
I am trying to add a new payment module into Magento. However, even after
I'm just starting my journey into OOP - and I'm currently trying to roll
I'm trying to write a simple php function that will strip everything between two
I'm currently trying to hide a dynamically created table row after a button has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.