require_once "Constants.php";
require_once "database.php";
require_once "fun_class.php";
$fun_class = new fun_class();
$database = new database();
$myConnection = $database->connect_database(SERVER,USER,PASSWORD,DATABASE);
I have this at the top of the page (header area- thats because I have session thing going on) and then I have a second php opening and closing tab at in the place where the filling is supposed to happen:
<select>
<?php
$fun_class->fillDropDownCategory($myConnection);
?>
</select>
In my fun_class.php I have this function:
function fillDropDownCategory($mysqli) {
echo " 1 ";
$display_block = "";
//Call Stored Procedure
if ($result = $mysqli->query("call rb_selectCategory()")) {
echo " 2 ";
// If there are no contacts returned
if ($result->num_rows < 1) {
//no records
echo " 3 ";
$display_block .= "<p><em>Sorry, no records to select!</em>
</p>";
} else {
echo " 4 ";
// For each record returned populate the select list
while ($recs = $result->fetch_object()) {
$id = $recs['category_id'];
$display_name = stripslashes($recs['name']);
$display_block .= "<option value=\'" . $id . "\'>" .
$display_name . "</option>";
}
}
//free result
$result->free();
//Get the last id entered - needed for the other tables
echo " 5 ";
//So you can run another stored proedure after a select
$mysqli->next_result();
}
else
{
echo " 6 ";
$display_block .= "<p><em>Sorry, no records to select!</em></p>";
}
echo " 7 ";
return($display_block);
}
When I enter the page the select is empty and when I enter the source code of the site I can see this:
<select>
1 6 7
</select>
Which is the output from my debugging echo'es
My stored procedure is:
BEGIN
SELECT category_id, name AS name
FROM xxx.category
ORDER BY name;
END
when executed (in the phpmyadmin) it returns two tables one called category_id with the id's and the second one is called name and it has category names that are assigned to the id's.
I am pretty new to php and there is probably something wrong with my function but because of the lack of experience I cannot find the mistake.