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 9230543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:51:05+00:00 2026-06-18T05:51:05+00:00

Got a mysqli/php code below where it will display results depending on option selected

  • 0

Got a mysqli/php code below where it will display results depending on option selected from the question drop down menu:

$selectedquestionqry = "
SELECT
QuestionNo
FROM
Question
WHERE
(QuestionId = ?)
";

global $mysqli;
$selectedquestionstmt=$mysqli->prepare($selectedquestionqry);
// You only need to call bind_param once
$selectedquestionstmt->bind_param("i",$_POST["question"]);
// get result and assign variables (prefix with db)
$selectedquestionstmt->execute(); 
$selectedquestionstmt->bind_result($selQuestionNo);
$selectedquestionstmt->store_result();
$selquestionnum = $selectedquestionstmt->num_rows();   


 while ($selectedquestionstmt->fetch()) {

if($_POST["question"] === '0') {
    echo "<p>All Questions - Total:(" . $selquestionnum . ")</p>" . PHP_EOL;
}else if($_POST["question"] !== '0') {
echo "<p><strong>Questions: </strong>" . $selQuestionNo . "</p>" . PHP_EOL;
}
}

DROP DOWN MENU:

 <select name="student" id="studentsDrop">
    <option value="0">All</option>
    <option value="23">Jay Hart</option>
    <option value="32">Bubba Wright</option>
    </select>

My question is that how can I get it so that if the user has selected ‘0’, then it will be able to select all questions from the db which are displayed in the question drop down menu?

The reason I am asking this is because in my echo else if($_POST["question"] !== '0') {
echo "<p><strong>Questions: </strong>" . $selQuestionNo . "</p>" . PHP_EOL;
}
, nothing is being echo when I select the All option, which to me makes me think that it is not displaying the echo due to this. If I select a single question from drop down menu, it is able to output it’s echo.

  • 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-18T05:51:06+00:00Added an answer on June 18, 2026 at 5:51 am

    you just need to modify your query:

    if($_POST["question"] === '0') {
        $selectedquestionqry = "SELECT QuestionNo FROM Question";
    } else {
        $selectedquestionqry = "SELECT QuestionNo FROM Question WHERE (QuestionId = ?)";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a piece of code below where it performs certain php/mysqli tasks on
I've got the code below to pull hex values from a database and create
For some reason when I changed my php code from mysql to mysqli everything
I've got a nice drop down list working which is getting populated from a
I have got 2 drop down list in my php form. Values in the
I got this PHP code: // connect to mysql require_once('includes/connect.php'); // include config include('includes/config.php');
I've got a php file echoing hashes from a MySQL database. This is necessary
Sorry, newbie question I know, however I've currently got mySQL results only showing when
I got the image path inserted in to database by the below code but
I'm having a problem with the a mysqli query I'm calling from a php

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.