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

[eluser]Mahn[/eluser]
Ahoy,

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
#2

[eluser]InsiteFX[/eluser]
foreach
#3

[eluser]Mahn[/eluser]
Yes, but the query will be different each time. Something like
Code:
SELECT * FROM forums WHERE category_id = $category['id']
#4

[eluser]DarkManX[/eluser]
you wont be able to avoid learning php. you should start by pure php without frameworks etc. there are enough good tutorials.
#5

[eluser]Mahn[/eluser]
@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.
#6

[eluser]InsiteFX[/eluser]
Controller
Code:
$data['cats'] = 'get the query from your model';
$this->load->view('your view', $data);

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

Something like that.
#7

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

[eluser]DarkManX[/eluser]
The model just returning you the date from the db. fetch them all in to an array and give it all to the view.
#9

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

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

Code:
$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->load->view('view',$data);

this way you could use $all_my_stuff in the view.




Theme © iAndrew 2016 - Forum software by © MyBB