gpt4 book ai didi

javascript - 它无法循环其他民意调查。它只能显示民意调查的第一个 id

转载 作者:行者123 更新时间:2023-11-29 16:49:09 24 4
gpt4 key购买 nike

它总是只出现一次民意调查。尽管我在数据库中保存了不同的民意调查。它总是可以显示数据库的第一个id。

<form action="" method="post" name="pollFrm">
<?php
//include and initialize Poll class
include 'Poll.class.php';
$poll = new Poll;

//get poll and options data
$pollResult= $poll->getPolls();
?>
<div class="pollContent">
<?php echo !empty($statusMsg)?'<p class="stmsg">'.$statusMsg.'</p>':''; ?>
<form action="" method="post" name="pollFrm">
<h3><?php echo $pollResult['poll']['subject']; ?></h3>
<ul>
<?php foreach($pollResult['name'] as $opt){
echo '<li><input type="radio" name="voteOpt" value="'.$opt['id'].'" >'.$opt['name'].'</li>';
} ?>
</ul>
<input type="hidden" name="pollID" value="<?php echo $pollResult['poll']['id']; ?>">
<input type="submit" name="voteSubmit" class="button" value="Vote">
<a href="results.php?pollID=<?php echo $pollResult['poll']['id']; ?>">Results</a>
</form>
</div>



</form>

这是获取民意调查的功能。我尝试删除单曲。但它不起作用。

 public function getPolls($pollType){
$pollData = array();
$sql = "SELECT * FROM ".$this->pollTbl." WHERE status = '1' ORDER BY created DESC";
$pollResult = $this->getQuery($sql, $pollType);
if(!empty($pollResult)){
if($pollType == 'single'){
$pollData['poll'] = $pollResult;
$sql2 = "SELECT * FROM ".$this->optTbl." WHERE poll_id = ".$pollResult['id']." AND status = '1'";
$optionResult = $this->getQuery($sql2);
$pollData['name'] = $optionResult;
}else{
$i = 0;
foreach($pollResult as $prow){
$pollData[$i]['poll'] = $prow;
$sql2 = "SELECT * FROM ".$this->optTbl." WHERE poll_id = ".$prow['id']." AND status = '1'";
$optionResult = $this->getQuery($sql2);
$pollData[$i]['name'] = $optionResult;
}
}
}
return !empty($pollData)?$pollData:false;
}

/* * 运行数据库查询 * @param 字符串 SQL * @param 字符串数量,单个,全部 */

private function getQuery($sql,$returnType = ''){
$result = $this->db->query($sql);
if($result){
switch($returnType){
case 'count':
$data = $result->num_rows;
break;
case 'single':
$data = $result->fetch_assoc();
break;
default:
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$data[] = $row;
}
}
}
return !empty($data)?$data:false;
}

最佳答案

您的函数 getPolls 有一个默认参数 $pollType = 'single',如果不向该函数传递任何内容,将导致其解析为默认参数“single”。

当该参数被传递给 getQuery 函数时,它总是只会得到一个。我建议完全删除默认参数并将方法更改为:

public function getPolls($pollType){

关于javascript - 它无法循环其他民意调查。它只能显示民意调查的第一个 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52915123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com