Welcome Guest, Not a member yet? Register   Sign In
How to do this?
#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.


Messages In This Thread
How to do this? - by El Forum - 07-26-2012, 03:15 PM
How to do this? - by El Forum - 07-26-2012, 09:26 PM
How to do this? - by El Forum - 07-27-2012, 06:42 AM
How to do this? - by El Forum - 07-27-2012, 11:44 AM
How to do this? - by El Forum - 07-27-2012, 06:45 PM
How to do this? - by El Forum - 07-27-2012, 09:22 PM
How to do this? - by El Forum - 07-28-2012, 04:14 AM
How to do this? - by El Forum - 07-28-2012, 04:18 AM
How to do this? - by El Forum - 07-28-2012, 04:34 AM
How to do this? - by El Forum - 07-28-2012, 04:42 AM
How to do this? - by El Forum - 07-28-2012, 09:34 AM
How to do this? - by El Forum - 07-29-2012, 04:20 PM
How to do this? - by El Forum - 07-30-2012, 04:17 PM
How to do this? - by El Forum - 07-30-2012, 05:31 PM
How to do this? - by El Forum - 07-31-2012, 04:15 AM
How to do this? - by El Forum - 07-31-2012, 11:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB