PHP/Codeigniter elseif未处理
我似乎无法在下面的php代码中处理elseif。我的数据库设置如下所示:PHP/Codeigniter elseif未处理,php,codeigniter,Php,Codeigniter,我似乎无法在下面的php代码中处理elseif。我的数据库设置如下所示: <?php // the following php is the bootstrapper for the friendship connector $selectedId = $_REQUEST['id']; $myuserid = $this->session->userdata('userid'); $friendshipQuery = $this->db->
<?php // the following php is the bootstrapper for the friendship connector
$selectedId = $_REQUEST['id'];
$myuserid = $this->session->userdata('userid');
$friendshipQuery = $this->db->query("SELECT * FROM friends");
$row = $friendshipQuery->row();
foreach ($friendshipQuery->result() as $row) {
if ($myuserid == $selectedId) { ?>
<script type="text/javascript">
$(document).ready(function() {
$("#addFriend").hide();
});
</script>
<?php } elseif ($row->relationType == 'requested') { ?>
<script type="text/javascript">
$(document).ready(function() {
alert("hello");
$("#addFriend").replaceWith(<input type="submit" value="Accept Friend" style="width: 95px; height: 28px" class="button1" />);
});
</script>
<?php } } ?>
$(文档).ready(函数(){
$(“#addFriend”).hide();
});
$(文档).ready(函数(){
警惕(“你好”);
$(“#addFriend”).replaceWith();
});
您是否检查了生成的html?如果它不包含该部分,则表示$myuserid==$selectedId
始终为真。您的问题就在这里:
$friendshipQuery = $this->db->query("SELECT * FROM friends");
$row = $friendshipQuery->row();
foreach ($friendshipQuery->result() as $row) {
将查询指定为->行()元素。将该行取出,在foreach上添加以下内容:
foreach($friendshipQuery->result() as $row)
这应该可以解决问题。请参考
$row=$friendshipQuery->row()不需要code>。elseif
仅在$selectedId
和$myuserid
不相等时才会运行。我将其更改为if语句,但仍然没有成功。请尝试变量转储($row->relationType)
,确保它是您想要的。如果删除if/elseif
使其始终得到执行,会发生什么情况?问题仍然存在。我想这可能与逻辑有关。你检查过生成的html了吗?