我想选择一个与团队的对比,我已经做了两个选择并从数据库中显示团队:我所做的是:
<p>
<label>Teams</label>
<select id="team1" name="team1">
<option disabled selected value>Team 1</option>
<?php
while ($team = $db->fetch_array($teams))
{
echo renderTeamsSelect($team);
}
$db->free_result($teams);
?>
</select>
VS
<select id="team2" name="team2">
<option disabled selected value>Team 2</option>
<?php
while ($team = $db->fetch_array($teams))
{
echo renderTeamsSelect($team);
}
$db->free_result($teams);
?>
</select>
</p>
请注意$ team是:
$teams = $db->query('SELECT * FROM teams');
我的函数renderTeamSelect是:
function renderTeamsSelect($team)
{
return '<option value="' . $team['id'] . '">' . $team['name'] . '</option>';
}
一旦我在html中看到结果,团队2就没有在选项中显示任何内容。
我添加了截图
我无法理解为什么选择一个显示结果并选择2否
答案 0 :(得分:1)
可能是你正在使用
$db->free_result($teams);
通过这种方式你可以释放结果
尝试仅在页面末尾执行此操作(省略第一个)
答案 1 :(得分:1)
更好的方法: -
data(ChickWeight)
df <- ChickWeight
df$Y <- 0
df$Y[df$weight > 100] <- 1
df$X <- df$Diet
df <- df[sample(nrow(df)),]
folds <- cut(seq(1,nrow(df)),breaks=10,labels=FALSE)
result <- list()
for(i in 1:10){
testIndexes <- which(folds==i,arr.ind=TRUE)
testData <- df[testIndexes, ]
trainData <- df[-testIndexes, ]
model <- glm(Y~X,family=binomial,data=trainData)
result[[i]] <- predict(model, testData)
}
result