我直接在我的标记呼应的出下面的标记为每个结果传递PHP参数传递给准备好的语句函数调用不工作
'<div class="checkboxwrapper"><input type="checkbox" name="checkbox[]" value="' . $userid . '">' . $name . '</div>'
具有所有这些额外的代码在我的标记,似乎有一个SELECT准备好的声明有点笨重。是否有可能以某种方式将这个准备好的语句保存在一个单独的文件中,将其包含在我的标记的顶部,然后根据我想要的结果调用函数传递一个单独的参数?
即
getresult.php
<?php
function getResults($output) {
global $db;
$stmt = $db->prepare("SELECT UserID, Name, Country FROM Dummy");
$stmt->execute();
$stmt->store_result();
$rows = $stmt->num_rows();
$stmt->bind_result($userid, $name, $country);
if($rows) {
while($stmt->fetch()) {
echo $output;
}
} else {
echo 'No Results found';
}
$stmt->close();
}
?>
indexp.php
<?php
getResults('<div class="checkboxwrapper"><input type="checkbox" name="checkbox[]" value="' . $userid . '">' . $name . '</div>');
?>
我似乎无法得到上面的代码工作,我怀疑它是做结果绑定? 理想情况下,id喜欢能够从不同的地方调用函数,并能够通过传递参数指定我想要返回的结果。这可能吗??
回声 '没有找到结果'; 此部分是否受到影响? – 2014-09-22 07:53:23