MySQLii prepared statements inside prepared statements.
Hello,
I'm currently coding a staff panel using mysqli prepared statements, but I'm stuck.
PHP Code:
public function BuildMenu($idd)
{
$stmt = $this->db->stmt_init();
$return = "";
if($stmt->prepare("SELECT parent_id, language_locale FROM hk_menu WHERE parent_id = 0 AND minrank <= ? ORDER BY order_id + 0"))
{
$stmt->bind_param("i", $this->server->site->GetDataByUsername($_SESSION['HK']['USERNAME'], "rank"));
$stmt->bind_result($parent, $locale);
$stmt->execute();
$data = $stmt->fetch();
$stmt->close();
while($data)
{
$return .= "<div class=\"box-container\">";
$return .= "";
$return .= "";
$return .= "";
$return .= "</div>";
}
}
else
{
LogError($this->db->error, "mysqli");
TriggerError("MySQLi Error", $this->db->error);
}
return $return;
}
But It's exceeding execution time, I know doing a prepared statement inside another won't work because you have to close first statement first, so i can't do while before closing the first statement, because inside that while there will be another prepared statement once i figure out this.
Any help would be much appreciated, Like + Rep <3
Re: MySQLii prepared statements inside prepared statements.
So this is what's causing problems, right?
PHP Code:
$this->server->site->GetDataByUsername($_SESSION['HK']['USERNAME'], "rank");
because you're asking for database data within the current statement?
If that's the case, why not just add
PHP Code:
$rank = $this->server->site->GetDataByUsername($_SESSION['HK']['USERNAME'], "rank");
At the very start of your function, so you have that variable localized to put into the bind_param
Re: MySQLii prepared statements inside prepared statements.
No that wasn't the problem, but i figured it out, i forgot to add $stmt->store_result(); problem fixed now.