$sql = "SELECT * FROM previousbroadcast ORDER BY id DESC";
$result=mysql_query($sql);
$count = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
if (isset($_POST['re_b'])){
$xml = simplexml_load_file($row['bclink']);
}
}
,HTML就像
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['id']; ?>">
答案 0 :(得分:1)
好的,这是一个新的尝试,其中包含您提供的其他信息:
此解决方案基于以下假设:
id
- 它可以在数据库中以不同方式命名,但只有您知道... 话虽如此:
$sql = "SELECT * FROM previousbroadcast ORDER BY id DESC";
$result=mysql_query($sql);
$count = mysql_num_rows($result);
// in this array, we now have all the values of the checkboxes the user selected
$checkboxvalues = $_REQUEST['checkbox'];
while ($row = mysql_fetch_assoc($result)) {
if (isset($_POST['re_b'])){
// if the ID of this row is mentioned in the checkboxes the user clicked
// then - and only then - load the file
if (in_array($row[id], $checkboxvalues)) {
$xml = simplexml_load_file($row['bclink']);
}
}
}
答案 1 :(得分:1)
您应该将获取的数组存储在另一个数组中,然后在那里进行迭代,而不是向数据库发出大量请求,这将使您的代码运行得更快,并且您可以更好地控制它。
答案 2 :(得分:1)
我会让SQL为你做所有的过滤:
if (isset($_POST['re_b'])) {
$checkboxvalues = isset($_REQUEST['checkbox']) ? $_REQUEST['checkbox'] : array();
$myCheckboxes = array();
foreach ($checkboxvalues as $cbv) {
$myCheckboxes[] = mysql_real_escape_string($cbv);
}
$sql = "SELECT * FROM previousbroadcast WHERE id IN ('" . implode(",", $myCheckboxes) . "') ORDER BY id DESC";
$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$xml = simplexml_load_file($row['bclink']);
// do something here with $xml or it will get overwritten
}
}