Welcome Guest, Not a member yet? Register   Sign In
Help needed with SQL query
#21

[eluser]RussC[/eluser]
Yes.
#22

[eluser]Brad K Morse[/eluser]
paste the query here
#23

[eluser]RussC[/eluser]
in the model
Code:
function getAllbyTeacher($id)
   {
        $c = new Course();

        $c->where('teacher_id', $id);
        $c->order_by('day', 'asc');
        $c->order_by('start', 'asc');

        return $c->get();

   }


in the controller...
Code:
function teacher()
    {
       $id = 2;
       $data['day'] = $this->Course->getAllbyTeacher($id);
       $data['times'] = $this->Course->getAllbyTeacher($id);

       $this->load->view('schedule', $data);

    }
#24

[eluser]Brad K Morse[/eluser]
You need to restructure your tables.

You will two queries, one for grabbing the days and courses they teach.

Then another query for grabbing the course end/start times.

Then loop thru each day, printing the course, then the corresponding start/end time for each course.

so the foreach loops would look like:

Code:
<?php foreach($day as $d): ?>
<?=$d->day_title?>

<?php foreach($course as $c):
  if($c->day_id = $d->id): ?>
  <?=$c->start_time?> - <?=$c->end_time?>
  <?php endif;
  endforeach; ?>

<?php endforeach; ?>

Didn't test it out, but you may need to restructure the table and then get the queries up and running, grabbing the appropriate data
#25

[eluser]RussC[/eluser]
Looks good. This restructure will take me some time, but well worth it. Thanks again for all your help!




Theme © iAndrew 2016 - Forum software by © MyBB