...

View Full Version : Prepared Statement Object Not Working Properly?



Cryotech
01-06-2012, 12:56 PM
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:



$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:
<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum