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

[eluser]mlakhara[/eluser]
You can use nested views for display.
At the first level you display the categories(using foreach) and in side this you can again load another view to display the forum topics under that category.
Also Data fetching can be don in the similar way using models for category and topics.

This way you will get the data in the form of a nested associativ array which then can be used easily with each nested view(as the associative arrays break inside the view).
#12

[eluser]Mahn[/eluser]
Okay, here's a very simple example of what I'm trying to do written with procedural php. So the following code simple creates a list of categories, and the corresponding forums underneath (where the category_id = the one being displayed)

Code:
$query = mysql_query("SELECT * FROM categories");
while ($row = mysql_fetch_array($query))
{
echo '<ul>';
echo '<li>'.$row['category_name'].'</li>';
echo '</ul>';

$query = mysql_query("SELECT * FROM forums WHERE category_id = {$row['category_id']}");
while ($row = mysql_fetch_array($query))
{
  echo '<ol>';
  echo '<li>'.$row['forum_name'].'</li>';
  echo '</ol>';
}
}

Which will make something like the following:

Code:
• Category 1
1. I belong to category 1
2. I also belong to category 1

• Category 2
1. I belong to category 2
2. I also belong to category 2
#13

[eluser]Mahn[/eluser]
bump!
#14

[eluser]Aken[/eluser]
http://ellislab.com/codeigniter/user-gui...index.html

If you know how to do it with procedural code, then read into how to do DB queries with CI, and apply it to your code. You say you know the basics, but you're not trying to apply any of them.

Try something, if it doesn't work, then show your code and ask specific questions, not just "how do I do this?".
#15

[eluser]astroanu[/eluser]
this can be easily achieved with with a foreach loop. As Aken said if you know how to do it with php its fairly simple with CI if you read the DB guide in CI
#16

[eluser]mlakhara[/eluser]
Oops!! I am sorry as I didn't check my mailbox for a while
This is how I achieved something like this for an online survey project which had a set of question which were divide into groups called "panel". each panel had a number of question which can be of varying type(MCQ,text answer,and other things which required variable markup for each question). I divided my view at each level.

at the most basic level I wrote the view for displaying a question like this
Code:
file -(view/question)

<label class="question">&lt;?php echo  $qtext;?&gt;</label>
&lt;?php
if($qtype == 1) //this is the text type question
{
     echo '&lt;input type="text" name="';
  echo $qid;
  echo '"/&gt;';
}
elseif ($qtype == 2) // Yes no type question
{
  echo '&lt;input name=';
echo $qid;
echo 'type="radio"&gt;Yes &lt;/input&gt;';
    echo '&lt;input name=';
echo $qid;
echo 'type="radio"&gt;No &lt;/input&gt;';
}
elseif($qtype == 3) // Select with variable options
{
//print_r($options);
echo '<select name="';
echo $qid;
echo '">';

foreach($options as $option)
{
  echo '<option>';
  echo $option;
  echo'</option>';
}
echo '</select>';
  
}
elseif($qtype == 4)//Five pointer question
{
  echo '&lt;input name="{$qid}" type="radio"&gt;Strongly Agree &lt;/input&gt;
          &lt;input name="{$qid}" type="radio"&gt;Agree &lt;/input&gt;
          &lt;input name="{$qid}" type="radio"&gt;Neutral &lt;/input&gt;
          &lt;input name="{$qid}" type="radio"&gt;Disagree &lt;/input&gt;
          &lt;input name="{$qid}" type="radio"&gt;Strongly Disagree&lt;/input&gt;';
}
elseif($qtype == 5)//Radio question with multiple options
{
  foreach($options as $option)
{
  echo '&lt;input name="{$qid}" type="radio"&gt;{option}&lt;/input&gt;';
}
}
else
{
  echo ('There is some error in view :- question');
}
?&gt;

now this view will be loaded for each question in the panel using looping
Code:
file -(view/question_panel)

<div class="form-panel ui-helper-hidden">
      <h1>&lt;?php echo $panelheading;?&gt;</h1>
     <fieldset class="ui-corner-all">                  
                    <br><br>
     &lt;?php foreach($questions as $question)
    // print_r($question);
      $this->load->view('question',$question);
     ?&gt;
     </fieldset>
</div>
this in turn was loaded using loops at the initial page where all this was to be shown
Code:
&lt;!-- This is where the question view will be looped and loaded --&gt;
    &lt;?php foreach($questionpanels as $questionpanel)
    {
    // print_r($questionpanel);
     $this->load->view('questionpanel',$questionpanel);
    } ?&gt;

So the last snippet was included in the main view that I requested, that way each level gets its seperate view system and you can tweak them easily.
If its complicated you can simply use the foreach loop as you just have to show the topics and nothing fancy like this
Code:
foreach($categories as $category)
{
  echo $category->title;
  foreach($category->topics as $topic) //$category->topics is an array of topics into this category
  {
   echo $topic;
}
}
You can format it and add anchor tag for navigationg to the topic, but I guess you get tha basic idea.

Oh yeah as far as OOP paradigm is concerned you should carry out all your queries in model, and seperate the application logic in controller.
And for this nothing is better than the CI user guide to read from.. :-)


Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB