MySQLi подготовил оператор в цикле while

Я пытаюсь выполнить 4 подготовленный оператор в mysqli_fetch_row while. В настоящее время мой код выводит NULL или пустые значения для всех запросов. Это мой первый раз с использованием подготовленных операторов, и я пытаюсь преобразовать свой код из mysql запросов в mysqli . Мой код ниже:

 $users = mysqli_query($link, "SELECT id FROM users WHERE approved = '1'"); while ($user = mysqli_fetch_row($users)) { if ($twitter_username_query = mysqli_prepare($username_query, "SELECT username FROM personas WHERE user_id = ?")) { mysqli_stmt_bind_param($username_query, "d", $user[0]); mysqli_stmt_execute($username_query); mysqli_stmt_bind_result($username_query, $username); mysqli_stmt_fetch($username_query); mysqli_stmt_close($twitter_username_query); } if ($count_user_clicks = mysqli_prepare($count_user_clicks, "SELECT count(distinct txid) FROM users_clicks WHERE user_id = ?")) { mysqli_stmt_bind_param($count_user_clicks, "d", $user[0]); mysqli_stmt_execute($count_user_clicks); mysqli_stmt_bind_result($count_user_clicks, $user_clicks); mysqli_stmt_fetch($count_user_clicks); mysqli_stmt_close($count_user_clicks); } if ($count_user_installs = mysqli_prepare("SELECT count(txid) FROM (SELECT txid FROM users_installs WHERE user_id = ? GROUP BY txid) table1")) { mysqli_stmt_bind_param($count_user_installs, "d", $user[0]); mysqli_stmt_execute($count_user_installs); mysqli_stmt_bind_result($count_user_installs, $user_installs); mysqli_stmt_fetch($count_user_installs); mysqli_stmt_close($count_user_installs); } if ($calc_user_cost = mysqli_prepare($calc_user_cost, "SELECT sum(earnings) FROM (SELECT max(cost) as earnings FROM users_clicks WHERE user_id = ? GROUP BY txid) table1")) { mysqli_stmt_bind_param($calc_user_cost, "d", $user[0]); mysqli_stmt_execute($calc_user_cost); mysqli_stmt_bind_result($calc_user_cost, $user_cost); mysqli_stmt_fetch($calc_user_cost); mysqli_stmt_close($calc_user_cost); } if ($user_clicks == '0') { $user_conv = 0; } else { $user_conv = ($user_installs / $user_clicks) * 100; } echo "<tr>"; echo "<td><b>".$username."</b></td>"; echo "<td>".number_format($user_clicks)."</td>"; echo "<td>".number_format($user_installs)."</td>"; if ($user_installs[0] == '0') { echo "<td>$0.00</td>"; } else { echo "<td>$".number_format($user_cost / $user_installs, 2)."</td>"; } echo "<td>".number_format($user_conv, 2)."%</td>"; echo "</tr>"; } 

Related of "MySQLi подготовил оператор в цикле while"