else语句正在显示 [英] else statement is displaying
本文介绍了else语句正在显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,当我执行它时,它没有显示任何结果。但是我没有在if-else条件下放置任何结果。实际结果:文本框,提交按钮,没有结果。我的预期结果是一个文本框,应该显示按钮而不是没有结果。没有搜索数据就不会显示结果。所以有人帮助我。
In this below code when i execuete it it shows no results.But i place no results in if-else condition .Actual result: textbox ,submit button and no results..My expected result is a textbox and button should be displayed and not no results.Without searching a data it displays no reults.So any one help me.
<form action="<?php echo site_url('search1_site/index');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" id="opn" value = "Search" />
</form>
<?php
if($results){
?> <div id='hideme'>
CLOSE<a href='#' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a> <div style="background:#FFFFFF; width: 500px; height: 500px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal" >
<table class="display2 table table-bordered table-striped">
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo "no results";
}
?>
</table></div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
推荐答案
检查请求是发帖请求还是默认页面负载
check the request is a post request or a default page load
使用
else if($_SERVER['REQUEST_METHOD'] === 'POST')
{
echo "no results";
}
而不是
else
{
echo "no results";
}
这篇关于else语句正在显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文