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

  • Home
  • SEARCH
  • 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 7025495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:58:57+00:00 2026-05-27T23:58:57+00:00

I’ve recently began learning Prepared Statements and have started configuring my scripts with the

  • 0

I’ve recently began learning Prepared Statements and have started configuring my scripts with the new style.

However, I ran into a little wall and I’m hoping someone can point me in the right direction?

Here is my SQL query structure:

$query = "SELECT `results`, `Success`, `Failure`, `Counter`, `Grades`, `Classes`,
`Special_Id`, `SpecialCondition` FROM `Courses` INNER JOIN `Students` ON `id` = 
`Students_Id` JOIN `Conditions` ON `id` = `Special_Id`";

$stmt = $Mconn->prepare($query);
$stmt->bind_result($results, $success, $failed, $counter, $grades, $classes,
$specialId, $specialcondition);
$stmt->execute();
$stmt->store_result();

And here is one code block:

<?php

echo "<select = \"SpecialConditions\">";
if($stmt->num_rows == NULL){
  echo "No results found.";
}else{
  while($stmt->fetch()){

   echo "<option value=\"$specialId\">$specialcondition</option>";
}
}
echo "</select>";
?>

And another code block:

<?php
echo "<select = \"Grades\">";
if($stmt->num_rows == NULL){
  echo "No results found.";
}else{
  while($stmt->fetch()){

      echo "<option value=\"".$grades."\">".$grades."</option>";
  }
}
echo "</select>";

?>

Ok, now what’s happening is if I place both of these queries on the same page, the first block will kill the second one and another query below it and I can’t figure out why and I’ve researched this to no end.

I’ve tried closing the connection within the same code block thinking that might do the trick but to no prevail.

Now, I do know that the DB connection is working and I do know that the returned results are actually being stored because if I test each block on a separate page, it works as it’s supposed to.

Thank you in advance for your help.

  • 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-05-27T23:58:58+00:00Added an answer on May 27, 2026 at 11:58 pm

    Nice, I got it to work finally. Everything needs to be stored in an array and extracted through that it seems. At least that’s the only way I got it to work properly.

    Here’s the final solution in case anyone is curious or hits this wall in the future. If you know of a way that does not require this method, please let me know.

    My Dynamic function that connects and queries the database:

    <?php
    
    function DB_Query(){
    $databasefields = array();
    $results = array();
    
    @$Mconn = new mysqli(DBHOST, DBUSER, DBPWRD, DBNAME);
    
       if (!@mysqli_connect(DBHOST, DBUSER, DBPWRD, DBNAME)){
         die(DBERROR);
       }
    
    $query = "SELECT `results`, `Success`, `Failure`, `Counter`, `Grades`, `Classes`,
    `Special_Id`, `SpecialCondition` FROM `Courses` INNER JOIN `Students` ON `id` =
    `Students_Id` JOIN `Conditions` ON `id` = `Special_Id`";
    
    $stmt = $Mconn->prepare($query);
    $stmt->execute();
    $meta = $stmt->result_metadata();
    
    while($field = $meta->fetch_field()){
    $databasefields[] = &$row[$field->name];
    }
    
    call_user_func_array(array($stmt, 'bind_result'), $databasefields);
    while($stmt->fetch()){
      $queried = array();
      foreach($row as $key => $vector){
           $queried[$key] = $vector;
      }
    
      $results[] = $queried;
    }
    
     return $results;
    }
    
    $results = DB_Query();  // placed in DB include file
    ?>
    

    And here’s the code I use to actually display the data singly or in multiple blocks. Just change the field name to correspond to yours. The function is dynamic and doesn’t require you to hard-code any binding results so you can fetch as many fields as desired.

    <?php
    foreach($results as $row){
    echo $row['grades'].'<br />';
    }
    

    Thanks for all the help and I hope this serves to help those that ran into the same problem as I did.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.