• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Processing query data to produce craigslist style categories with row counts.

#3
[eluser]Ollie Rattue[/eluser]
[quote author="Hannes Nevalainen" date="1218558287"]You need to join your tables =)

It can be little tricky at first but it's really worth digging in to it! =)
Find a nice tutorial on this (google for tutorial mysql join) and you will get lucky ^^

Happy Coding =)[/quote]

So I looked into Joins and it turns out they are kind of useful Smile My current model looks like this:
Code:
function browse($category, $status) {
$this->db->select(array('manufacturers.manufacturer','models.model'));
$this->db->from('manufacturers');
$this->db->join('models', 'models.manufacturerid = manufacturers.id');
$this->db->join('items','items.modelid = models.id');
$this->db->where('category', $category);
$this->db->where('status', $status);
$this->db->orderby( 'manufacturers.manufacturer', 'asc' ); // puts it into alpabetical order
$query = $this->db->get();
}

I then call this from my controller and pass the results onto my view file like so:

Code:
$data['results'] = $this->buysellmodel->browse('mp3 players','live');
$this->load->view('welcome/browse', $data);

Which works nicely at giving me a list of all the manufacturers and models of all the live items in my database for sale. Not overly relevant but I forgot to mention that my items can be live, discontinued or pending.

However what I can't work out is how I loop through this information to produce a nice list of manufacturers with their corresponding models with counts for individual models and manufacturers.

I have tried a few

Code:
foreach($results->result() as $row):

loops but it is very tricky to echo things out at the right point. What I think I have to do is read the information into an array and then print each manufacturer and model section when I have the counts for the various sections. But I can't get my head around how I can do this.

Again I really need some help or a nudge in the right direction.


Messages In This Thread
Processing query data to produce craigslist style categories with row counts. - by El Forum - 08-19-2008, 02:20 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.