Welcome Guest, Not a member yet? Register   Sign In
How to do this?


I'm currently trying to make a small forum software, so on the homepage I want to list categories and the forums that belong to the category underneath.

I'm used to making a while loop inside a while loop, so I have no idea how to do this with CodeIngiter.

Please let me know if that didn't make much sense Smile


Yes, but the query will be different each time. Something like
SELECT * FROM forums WHERE category_id = $category['id']

you wont be able to avoid learning php. you should start by pure php without frameworks etc. there are enough good tutorials.

@DarkManX: Why would you assume that? I've done this many times before with procedural PHP. I just can't make sense of how to do this with a model.

$data['cats'] = 'get the query from your model';
$this->load->view('your view', $data);

// View
    &lt;?php foreach ($cats as $cat): ?&gt;
        <li>&lt;?php echo $cat; ?&gt;</li>
    &lt;?php endforeach; ?&gt;

Something like that.

@InsiteFX: I've already got the categories done, it;s just the forums that are a bit tricky because the query changes every time.

The model just returning you the date from the db. fetch them all in to an array and give it all to the view.

@DarkManX: Yes, but the query changes for every category, so I can't just query for everything. The query will look something like:
SELECT * FROM forums WHERE category_id = $category['id']

Just get all categories and create a db-request for each of them. as i told, you wont be able to avoid learing php.

$all_cats = // get all cat, how every you want/got to
foreach($all_cats as $cat){
   $data['all_my_stuff'][] = // getting ur stuff with $cat

this way you could use $all_my_stuff in the view.

Theme © iAndrew 2016 - Forum software by © MyBB