php - Codeigniter: getting a user name with id -
i've got project i'm working on in, user can register , assigned id. user has ability post blogs or comment, these blogs or comments assigned authorid same users userid.
i need way name posted below these blogs or messages instead of id-which does.
my blog controller handles blog posting (commenting similar) exception of add together blog function:
function blogtoevoegen() { $this->form_validation->set_rules('blogtitel', 'blogtitel', 'min_length[3]|required|xss_clean|callback_username_check'); $this->form_validation->set_rules('blogtekst', 'blogtekst', 'min_length[2]|required|xss_clean'); if ($this->form_validation->run() == false) { $this->load->view('view_page', $this->view_data); } else { $data = array( 'id' => $this->input->post('id'), 'blogtitel' => $this->input->post('blogtitel'), 'blogtekst' => $this->input->post('blogtekst'), 'auteur_id' => $this->session->userdata('gebruiker_id'), ); $this->db->set('datum', 'now()', false); $this->db->insert('blogs', $data); redirect('blog/eigenblogs'); } }
a function handles displaying of blog post (it gets comments linked blog)
function comments() { $this->db->where('id', $this->uri->segment(3)); $this->db->select('blogtitel, blogtekst, auteur_id, datum'); $data['query2'] = $this->db->get('blogs'); $this->db->where('boodschap_id', $this->uri->segment(3)); $data['query'] = $this->db->get('comments'); $data ["titel"] = "pxl - comment"; $data ["pagina"] = "content_comment"; $this->load->view("view_page", $data); }
the view code displays these blogs (left code comments out)
<?php foreach ($query2->result() $rij): ?> <div class="post"> <h2><?= $rij->blogtitel ?></h2> <p><?= $rij->blogtekst ?></p> <p class="meta">posted <a href="#"><?= $rij->auteur_id ?></a> on <?= $rij->datum ?> </p> </div> <?php endforeach; ?> <hr>
i need way alter auteur_id name (made out of combination first + lastly name).
what need here called sql join. find more in ci manual:
here illustration of need:
$this->db->select('*'); $this->db->from('blogs'); $this->db->join('users', 'users.id = blogs.author_id'); $query = $this->db->get();
this blog posts , query user in users table based on author_id.
php database codeigniter
No comments:
Post a Comment