Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2012, 11:56 AM   PM User | #1
Cryotech
New to the CF scene

 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Cryotech is an unknown quantity at this point
Prepared Statement Object Not Working Properly?

Hello all,

First, I love this site and the awesome advice and knowledge that is shared within these pages

I was also hoping someone could help me solve an issue that will most likely be minor to those that know this stuff.

I'm not new to PHP/MySQL but I am finally, after a lengthy procrastination period, learning Prepared Statements.

During my learning, I ran into a wall regarding displaying two or more results on a single page.

Here is how I'm making a connection and query:

Code:
$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 herere is some code to help you see what I'm talking about:

Code:
Code:
<table>
<tr>
<td>
// The below code will display a selection box containing various strings such as "hello world", "great to be here", "Wowserz", "this is mind blowing" etc. that are stored in the database.

<?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>";
?>
</td>
<td>
// If I place another fetch query below the above fetch() query, this one will not show up. This one is supposed to display values 1 - 20 that have been stored in the DB.

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

?>

</td>
</tr>
</table>
As the notes inside the code state, if I place just one code block attempting to display results, it works fine. However, if I place more than one, the top code block kills those below it. I've tried closing the connection which did not help.

What am I doing wrong or what should I be doing to fix this?

Thanks for any advice in advance.
Cryotech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:07 PM.


Advertisement
Log in to turn off these ads.