Welcome Guest, Not a member yet? Register   Sign In
Nested Query Question (NEWBIE)
#1

[eluser]JesseR[/eluser]
Hi,

I am new to CI and having some issues accomplishing what I thought a simple objective.
I need to run some nested queries. Example shown below shows retreiving ITEMS
from the database of one table and then the price from another table. I then
need to attatch the SELLPRIC to the matching record in the array to be able
to display the ITEM and its price in the view.

There are various reasons why I have chosen to do these as completely seperate queries.
I know it can be accomplished in other ways but this is the way we need to do it.

Can anyone advise how to accomplish this and display it? I can't seem to get
SELLPRIC attatched properly to query result array.

Your help is much appreciated.


CONTROLLER:

$this->db->where('CATEGORY','BECAS'/*$this->uri->segment(3)*/);
$this->db->like('DESCRIPT', '1 1/2"');
$data['query_item'] = $this->db->get('ITEMS');

foreach($data['query_item']->result() as $row):

echo $row->ITEMNO;
echo "this is the price:";


/* Get Standard Item Selling Price */

$this->db->select('SELLPRIC');
$this->db->where('ITEMNO',$row->ITEMNO);
$this->db->where('MEAS_TYPE',1);
$data['query_price'] = $this->db->get('ITEM_MEASURE');
foreach($data['query_price']->result() as $row2):
$data['query_item']->SELLPRIC = $row2->SELLPRIC;
echo $row2->SELLPRIC;
echo "<br>";

endforeach;

endforeach;

VIEW:

&lt;?php foreach($query_item->result() as $row): ?&gt;
<h3>&lt;?=$row->DESCRIPT?&gt;</h3>
<p>&lt;?=$row->WEBDESC?&gt;</p>
<p>&lt;?=$row->SELLPRIC?&gt;</p>

<p>&lt;?=anchor('blog/comments/'. $row->ITEMNO, 'Comments');?&gt;</p>
<hr />
&lt;?php endforeach; ?&gt;


Messages In This Thread
Nested Query Question (NEWBIE) - by El Forum - 01-13-2010, 03:49 PM
Nested Query Question (NEWBIE) - by El Forum - 01-13-2010, 04:38 PM
Nested Query Question (NEWBIE) - by El Forum - 01-13-2010, 04:55 PM
Nested Query Question (NEWBIE) - by El Forum - 01-13-2010, 05:26 PM
Nested Query Question (NEWBIE) - by El Forum - 01-13-2010, 11:05 PM
Nested Query Question (NEWBIE) - by El Forum - 01-14-2010, 03:35 AM
Nested Query Question (NEWBIE) - by El Forum - 01-14-2010, 07:12 AM
Nested Query Question (NEWBIE) - by El Forum - 01-14-2010, 08:42 AM
Nested Query Question (NEWBIE) - by El Forum - 01-14-2010, 12:08 PM
Nested Query Question (NEWBIE) - by El Forum - 01-14-2010, 03:08 PM
Nested Query Question (NEWBIE) - by El Forum - 01-15-2010, 03:15 AM
Nested Query Question (NEWBIE) - by El Forum - 01-15-2010, 07:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB