Welcome Guest, Not a member yet? Register   Sign In
Codeigniter model pass value controller to view with join tables
#1

[eluser]webmarkcompt[/eluser]
Hi all,

I having a problem passing values ​​in a column according to the id of the product.

The join tables is running but returns all column values. I think the solution is simple but I am not able to get there. Please some help to solve this issue?

Here is the tables

TABLE: tbl_lining
id, article, description, observations

TABLE:products

[Table Products - picture] http://goo.gl/jjUXyy

Function used in model


MODEL
Code:
public function getliningsale($id)
{
    $this->db->select('*');
    $this->db->from('products');
    $this->db->join('tbl_lining', 'products.lining=tbl_lining.id', 'left');
    $this->db->where('products.id', $id);  // Also mention table name here
    $query = $this->db->get();    
    if($query->num_rows() > 0)
        return $data->result();
}

CONTROLLER

Code:
function liningsale()
{  

$data['lining'] = $this->sales_model->getliningsale($id);
$this->load->view('add', $data);
}

Trying to display one record according product id

VIEW

Code:
echo '<td>&lt;input class="span1 tran2" name="lining\\'+ count +\\'" type="text"';
echo 'value="';
foreach ($lining as $valor) {
echo $valor-&gt;article;
echo '-';
echo $valor-&gt;description;
echo '">';
}

echo '</td>';


Instead of that, is displaying all records

[Table Result - picture](http://goo.gl/BhHunM)


Can anyone please help me to solve this issue?

#2

[eluser]InsiteFX[/eluser]
As far as the id it depends on what you are passing to the model method.

Code:
foreach ($liningsale as $valor) {

// should be
foreach ($lining as $valor) {
#3

[eluser]webmarkcompt[/eluser]
Sorry,
I've done too many changes that I ended up copying the wrong function.

Posting a var_dump($query->num_rows()); it appears that the ID is null.

int(0) SELECT * FROM (`products`) LEFT JOIN `tbl_lining` ON `products`.`lining`=`tbl_lining`.`id` WHERE `products`.`id` IS NULL

So... I supose that's the problem. I can't figure out the solution to solve it..

Any sugestion?


#4

[eluser]InsiteFX[/eluser]
You need to pass an id to the method.

Usually this done but getting it from a table that lists all the records with actions [edit, delete etc;]

#5

[eluser]webmarkcompt[/eluser]
That's the tricky part...

This is a table of orders that loads the data via jquery (see picture here pls goo.gl/6Jl7XO).

The script was already functional. Was not made by me. I just need to add more information to it.

Seeking only the IDs stored in each column without JOIN, (lining / leather / others) the query is successful, with display of the IDs store in columns.

If I put here the code You can take a look?
#6

[eluser]CroNiX[/eluser]
In your controller/liningsale method, you are:
Code:
$data['lining'] = $this->sales_model->getliningsale($id);

Where is $id coming from? It's not in the code, so it appears to be undefined
#7

[eluser]webmarkcompt[/eluser]
Model:

Code:
public function getliningsale($id)
{
    $this->db->select('*');
    $this->db->from('products');
    $this->db->join('tbl_lining', 'products.lining=tbl_lining.id', 'left');
    $this->db->where('products.id', $id);  // Also mention table name here
    $query = $this->db->get();    
    if($query->num_rows() > 0)
        return $data->result();
}
That id should be from model?

Note that I never worked with codeigniter. Maybe I'm not doing the right process.
Any help would appreciate
#8

[eluser]CroNiX[/eluser]
Your model seems correct. Your controller isn't as that's what's passing the $id to the model, but it's not defined in the controller before you pass it.
#9

[eluser]webmarkcompt[/eluser]
How can I define that in the controller?
#10

[eluser]CroNiX[/eluser]
Hard to tell exactly as there seems to be a lot of missing code that is relevant. It looks like it might come from the form data but the partial code you posted doesn't show the rest. You also mention using jQuery to load the data but don't show that code either.




Theme © iAndrew 2016 - Forum software by © MyBB