Pergunta

Model

$q2 = "SELECT a.id, name, price FROM product a inner join detail b 
on a.id = b.id
WHERE a.id IN ('".$id."') and status = 1 ";
$result = $this->db->query($q2);
return $result->result_array();

where $id = 41001,41002

so, i try it into phpmyadmin. here's the result

phpmyadmin

SELECT a.id, name, priceFROM product a inner join detail b 
on a.id = b.id
WHERE a.id IN (41001,41002) and status = 1 

the result of that query are :

id     name        price
41001  Coca Cola   4500
41002  Pepsi       4500

View

<?php foreach($resultsearch as $r){?>
  <li class="span3">
    <div class="product-box">
      <?php echo $r['id']?>
      <?php echo $r['name']?><span><br/>
      <span>Rp. <?php echo number_format($r['price'],2,",",".")?></span><br/>
    </div>
  </li>       
 <?php $no++;}?>

but, only display

41001  Coca Cola   4500

how can I display like result of query in phpmyadmin?

Foi útil?

Solução

try your query like this

$q2 = "SELECT a.id, name, price FROM product a inner join detail b 
on a.id = b.id
WHERE a.id IN (".$id.") and status = 1 ";
$result = $this->db->query($q2);
return $result->result_array();

Outras dicas

try

echo $result->num_rows();

If the result is 2, then you have a problem in the controller, you must have something like this:

$this->load->view('myview', Array('resultsearch' => $this->MYMODEL->myquerymethod($id)));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top