这是我的代码:
观点:
<form method="post" action="<?php echo base_url(); ?>index.php/rbts/get_songs">
<div class="form-group">
<!-------------------------------------------------------- TOP Songs-------------------------------------------------------------->
<label class="col-sm-2 control-label">Top 1</label>
<div class="col-sm-10">
<select name="drptop_1" id="drptop_1" class="form-control m-b">
<?php
$n = 1;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
<label class="col-sm-2 control-label">Top 2</label>
<div class="col-sm-10">
<select name="drptop_2" id="drptop_2" class="form-control m-b">
<?php
$n = 2;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">Top 3</label>
<div class="col-sm-10">
<select name="drptop_3" id="drptop_3" class="form-control m-b">
<?php
$n = 3;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">Top 4</label>
<div class="col-sm-10">
<select name="drptop_4" id="drptop_4" class="form-control m-b">
<?php
$n = 4;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">Top 5</label>
<div class="col-sm-10">
<select name="drptop_5" id="drptop_5" class="form-control m-b">
<?php
$n = 5;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
<!-------------------------------------------------------- New Songs-------------------------------------------------------------->
<hr height="5px" width="100%">
<label class="col-sm-2 control-label">New 1</label>
<div class="col-sm-10">
<select name="drptop_6" id="drptop_6" class="form-control m-b">
<?php
$n = 6;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">New 2</label>
<div class="col-sm-10">
<select name="drptop_7" id="drptop_7" class="form-control m-b">
<?php
$n = 7;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">New 3</label>
<div class="col-sm-10">
<select name="drptop_8" id="drptop_8" class="form-control m-b">
<?php
$n = 8;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div> <br><br>
<label class="col-sm-2 control-label">New 4</label>
<div class="col-sm-10">
<select name="drptop_9" id="drptop_9" class="form-control m-b">
<?php
$n = 9;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
<label class="col-sm-2 control-label">New 5</label>
<div class="col-sm-10">
<select name="drptop_10" id="drptop_10" class="form-control m-b">
<?php
$n = 10;
foreach($songs as $song){
if($song['id']==$n){
?>
<option value="<?php echo $song['rbt_id']; ?>" selected><?php echo $song['title']; ?></option>
<?php
}
else if($song['id']==null){
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo "--------" ?></option>
<?php
}
else{
?>
<option value="<?php echo $song['rbt_id']; ?>"><?php echo $song['title']; ?></option>
<?php
}
}
?>
</select>
</div>
<br><br>
</div>
</div>
<div class="modal-footer">
<a href="<?php echo base_url(); ?>index.php/rbts/get_songs/" class="btn btn-default">Save</a>
<a href="#" class="btn btn-default" data-dismiss="modal">Close</a>
</div>
</form>
控制器:
public function get_songs(){
$top1=$this->input->get_post('drptop1');
$top2=$this->input->get_post('drptop2');
$top3=$this->input->get_post('drptop3');
$top4=$this->input->get_post('drptop4');
$top5=$this->input->get_post('drptop5');
$new1=$this->input->get_post('drptop6');
$new2=$this->input->get_post('drptop7');
$new3=$this->input->get_post('drptop8');
$new4=$this->input->get_post('drptop9');
$new5=$this->input->get_post('drptop10');
die(var_dump($top1));
//$this ->rbt->update_all_songs($top1,$top2,$top3,$top4,$top5,$new1,$new2,$new3,$new4,$new5);
}
之后它总是说bool(false). =.=
答案 0 :(得分:0)
您获得bool(false)
,因为$ top1中没有值。
其次,表单中的输入名称与您用于获取值的变量名称不同。
Example:
<select name="drptop_1" id="drptop_1" class="form-control m-b"></select>
AND
$top1=$this->input->get_post('drptop1');
尝试使用相同的输入名name="drptop_1"
和php变量名get_post('drptop1')
希望这有用。