您所做的几乎相同,只是更改了查询位。
要从charity_donor 中选择id 为25 的所有记录,您将执行以下查询:
SELECT *
FROM donor_charity
WHERE id = 25
现在要查询这个,首先你必须准备它:
$stmt = $mysqli->prepare("
SELECT *
FROM donor_charity
WHERE id = ?
");
现在要遍历结果,您必须绑定参数并执行查询。
$stmt->bind_param('d', 25 ); // First param means the type of the value you're
passing. In this example, d for digit.
$stmt->execute();
然后你设置一个数组来保存从查询返回的数据,
$row = array();
stmt_bind_assoc($stmt, $row);
现在循环返回的数据。
while ( $stmt->fetch () ) {
print_r($row); // Should now contain the column.
}
有关文档,请参阅:
准备:http
:
//www.php.net/manual/en/mysqli.prepare.php 绑定参数:http ://www.php.net/manual/en/mysqli-stmt.bind-param .php
执行:http
://www.php.net/manual/en/mysqli-stmt.execute.php 获取:http ://www.php.net/manual/en/mysqli-stmt.fetch.php