Welcome Guest, Not a member yet? Register   Sign In
MySQL Join Tables
#1

[eluser]codedoode[/eluser]
I'm having trouble joining 2 tables together using. I've tried doing a google search as well as here, and I'm a bit clueless as to why this isn't working the way I want it too. Can someone please lend a helping hand?

THIS IS MY CONTROLLER
Code:
<?php

class Site extends CI_Controller
{
public function index()
    {
  $this->load->model('Site_model');
  
  $config["base_url"] = base_url() . "/site/index";
  $config["total_rows"] = $this->Site_model->record_count();
  $config["per_page"] = 20;
  $config["uri_segment"] = 3;
  $choice = $config["total_rows"] / $config["per_page"];
  $config["num_links"] = round($choice);
  
  $this->pagination->initialize($config);
  
  $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;
  $data["results"] = $this->Site_model->fetch_submissions($config["per_page"], $page);
    
  $this->load->view('list_view', $data);
    }

THIS IS MY MODEL
Code:
<?php

class Site_model extends CI_Model {

    public function record_count()
    {
        return $this->db->count_all("submissions");
    }

    public function fetch_submissions($limit, $start)
    {
        $this->db->limit($limit, $start);
        $this->db->select('*');
$this->db->from('submissions');
$this->db->join('votes', 'votes.id = submissions.id');
        $query = $this->db->get("submissions");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }
}

THIS IS MY ERROR MESSAGE
Code:
Error Number: 1066

Not unique table/alias: 'submissions'

SELECT * FROM (`submissions`, `submissions`) JOIN `votes` ON `votes`.`id` = `submissions`.`id` LIMIT 20

Filename: /Applications/MAMP/htdocs/ttaa/models/site_model.php

Line Number: 34
#2

[eluser]limit[/eluser]
I havent messed with joins via the active record a whole lot , but maybe  try.

Code:
$query = $this->db->get("submissions");
to
 
Code:
$query = $this->db->get();
#3

[eluser]codedoode[/eluser]
[quote author="limit" date="1327817320"]I havent messed with joins via the active record a whole lot , but maybe  try.

Code:
$query = $this->db->get("submissions");
to
 
Code:
$query = $this->db->get();
[/quote]

Thanks for helping!




Theme © iAndrew 2016 - Forum software by © MyBB