Welcome Guest, Not a member yet? Register   Sign In
Having trobles with data from DB
#1

I currently have this code in my controller:

PHP Code:
   public function profile($username){
 
       
        
// Check Login
 
       if(!$this->session->userdata('user_id')){
            
// Redirect to page
            
redirect('users/login');
 
       }

 
       // Get user info
 
       $data['item'] = $this->User_model->get_username($username);
 
       $user $this->User_model->get_username($username);
 
       
        
// Meta
 
       $data['title' $this->settings->title.' | '.ucfirst($user->username);
 
       $data['description' ucfirst($user->biography);

 
       // Already friends?
 
       $data['relationship'] = $this->User_model->the_relationship($user->id);

 
       // If empty show a 404 error
        
if(empty($data['item'])){
            
show_404();    
        }
                    
 
       // Load template
 
       $this->template->load('public''default''users/profile' $data);
        
 
   

and this in my model:

PHP Code:
   // Relationship for single
 
   public function the_relationship($id){    
    
$this->db->select('*');
 
       $this->db->from($this->relationship);
 
       $this->db->where('user_id'$this->session->userdata('user_id'));
 
       $this->db->where('friend_id'$id);
 
       $this->db->where('type'$this->type);

        
$query $this->db->get();

        if(
$query->num_rows() >= 1){
            return 
$query->row();
        } else {
            return 
false;
        }
    } 

and this is my view:

PHP Code:
       <?php if($item->username == $this->session->username) : ?>
        <!-- If friendship accepted - You can cancel the friendship request to this user -->
        <?php elseif($relationship->status == 'accepted') : ?>
            <?= form_open('users/unfollow/'.$item->id.'/'.$item->username) ; ?>
                <?php $data = array(
 
                   'name'  => 'friend_id',
 
                   'id'    => 'friend_id',
 
                   'value' => $item->id,
 
               ); ?>
                <?= form_hidden($data); ?>
            <?= form_submit('mysubmit''Unfollow', array('class' => 'btn btn-warning btn-xs')); ?>
            <?= form_close(); ?>
        <!-- If friendship pending - You can cancel the friendship request to this user -->
        <?php elseif($relationship->status == 'pending') : ?>
            <?= form_open('users/unfollow/'.$item->id.'/'.$item->username) ; ?>
                    <?php $data = array(
 
                       'name'  => 'friend_id',
 
                       'id'    => 'friend_id',
 
                       'value' => $item->id,
 
                   ); ?>
                    <?= form_hidden($data); ?>
                <?= form_submit('mysubmit''Pending - Cancel Friend Request', array('class' => 'btn btn-warning btn-xs')); ?>
            <?= form_close(); ?>
        <!-- If no friendship exists whatsoever - You can send a friendship request to this user -->
        <?php else : ?>
            <?= form_open('users/follow/'.$item->username) ; ?>
                <?php $data = array(
 
                   'name'  => 'friend_id',
 
                   'id'    => 'friend_id',
 
                   'value' => set_value('friend_id'),
 
               ); ?>
                <?= form_hidden($data); ?>
            <?= form_submit('mysubmit''Follow', array('class' => 'btn btn-warning btn-xs')); ?>
            <?= form_close(); ?>
        <?php endif; ?>


The problem is when there is not existing relationship(friendship). Let's say when I visit a user which is already my friend, it shows me the proper button "the unfollow"(friendship; status: accepted) and it shows the proper button as well when the friendship is in status: pending.

Now when I visit a user which is not my friend(when there's not friendship), it should display the last button which is the follow button but the current output is an error of "error handler"

Can somebody tell me where is my error?
I do Front-End development most of the time 
Reply


Messages In This Thread
Having trobles with data from DB - by kirasiris - 07-27-2018, 04:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB