Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
While looping through an array of values, there is a check that needs to be performed against the database.

What I have tried:

View: kanban_v1.php


HTML
<html>
  <head>
    <title>Kanban</title>
  </head>

  <body>
    <table border=1>
      <?php
        $maxrowspan = 0;

        $tmp_level1_parent_columns = array();

        $level1 = array();
        $level2 = array();
        $level3 = array();

        foreach ($level1_parents as $row)
        {
          $parent_colspan = 0;

          //1. Insert parent columns; for looping
          array_push($tmp_level1_parent_columns, $row->child_id);

          //2. START FOREACH LOOP { Select child columns from P&C where parent_id = current_index <---- NEEDS TO QUERY DATABASE
          //SELECT child_id FROM parent_child_columns WHERE parent_id = $current_parent_id;
          $tmp_children = array();

          //3. Identify level of each child from tmp_children: 
          //$level = SELECT COUNT(parent_id) FROM parent_child_columns WHERE parent_id = $current_parent_id (or $row->child_id);

          //4. If $level > $maxrowspan, set $maxrowspan = $level.
          //5. If ($level == 2) { array_push($level2, $row->child_id => $level); }
          //5. If ($level == 3) { array_push($level3, $row->child_id => $level); }
          //} END OF FOREACH LOOP

          //6. Insert parent column into $level1. array_push($level1, $row->child_id => count($tmp_children))
        }
        echo count($level1_parent_columns);
       ?>
    </table>
  </body>

</html>



Controller: table.php

<?php

class table extends CI_Controller {

  function index()
  {
    $this->load->model('kanbandb');


    $data['level1_parents'] = $this->kanbandb->getLevel1Parents(1);
    $this->load->view('kanban_v1',  $data);
  }
}
 ?>


Model:
<?php
class kanbandb extends CI_Model {

  function getLevel1Parents($board_id)
  {
    $sql = " SELECT *
    FROM parent_child_columns
    WHERE board_id = {$board_id}
    AND parent_id = 0
    ";

    $query= $this->db->query($sql);
    $result = $query->result();
    $result_count = $query->num_rows();

    return $result;
  }
}
 ?>
Posted
Updated 21-Dec-16 18:24pm
v3
Comments
Suvendu Shekhar Giri 22-Dec-16 0:25am    
What is the issue here?
Please explain if you have a problem.
kmllev 28-Dec-16 1:48am    
I was wishing to know how I could run an SQL query directly from a view.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900