社交网络的棘手代码逻辑

时间:2012-07-27 19:12:21

标签: php codeigniter

Node1id是发送请求的用户,node2id是接收请求的用户。我如何限制下面的代码只显示对node2id的请求。我试过了:

$row->relationType == 'requested' && node2id == $userid

但它似乎不想工作。有什么想法吗?

enter image description here

<?php
$selectedId = $_REQUEST['id'];
$myuserid = $this->session->userdata('userid');
$query1 = $this->db->query("SELECT * FROM friends WHERE node1id = '{$myuserid}' AND node2id = '${selectedId}'");
      foreach($query1->result() as $row) {
      if ($row->relationType == 'requested') { ?>
            <script type="text/javascript">
                $(document).ready(function() {
                    $("#addFriend").replaceWith('<span id="requestAlert"><span class="font1">wants to be your friend&nbsp;</span><input type="submit" id="acceptRequest" value="Accept" style="width: 60px; height: 28px" class="button1" />&nbsp;<input type="submit" id="denyRequest" value="Deny" style="width: 50px; height: 28px" class="button1" /></span>');
                });
            </script>
<?php } } ?>

1 个答案:

答案 0 :(得分:2)

编辑:根据您的评论。以下是我认为应该从您的描述中看出来的内容:

<?php
  $selectedId = $_REQUEST['id'];
  $myuserid = $this->session->userdata('userid');
  $query1 = $this->db->query("SELECT * FROM friends WHERE relationType = 'requested' AND node2id = '${myuserid}' AND node1id ='$selectedId'");
  foreach($query1->result() as $row) { ?>
       <script type="text/javascript">
          $(document).ready(function() {
             $("#addFriend").replaceWith('<span id="requestAlert"><span class="font1">wants to be your friend&nbsp;</span><input type="submit" id="acceptRequest" value="Accept" style="width: 60px; height: 28px" class="button1" />&nbsp;<input type="submit" id="denyRequest" value="Deny" style="width: 50px; height: 28px" class="button1" /></span>');
          });
       </script>
  <?php }  ?>