⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Mutiple records one user_id



shawn_gl
  • profile picture
  • Member

Posted 19 June 2015 - 20:04 PM

  1. Hello i am also new to Codeigniter and Grocery Crud but is a great design

          My question is i think maybe a little advanced but curious on how to create a custom function similar to the below

          code.

  

          The function and controller i would like to get an answer to is how to store mutiple records for a single user_id

          in other words on the main screen for records i only need 1 user_id shown in the records area based on user_id table

          in sql ?

 

         I am comfrotable with SQL but having problems deciding how to display mutiple records for only 1 user_id

        

         The database is going to be for patient forms and the patient can only view there records only but each patient 

         will need multiple consultations recorded.

 

          SELECT * FROM user_id

 

          the above statement is the basis of what i need -- what i presume i need is a mutiple array passed as data

          but how would you access that with above SELECT statement ?

 

          Thank you in advance

          spending to many hours trying for solutions !

 

 

              

 

 

  1.  
  2. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3.  
  4. class Custom_query_model extends grocery_CRUD_model {
  5.  
  6.     private $query_str = '';
  7.     function __construct() {
  8.         parent::__construct();
  9.     }
  10.  
  11.     function get_list() {
  12.         $query=$this->db->query($this->query_str);
  13.  
  14.         $results_array=$query->result();
  15.         return $results_array;        
  16.     }
  17.  
  18.     public function set_query_str($query_str) {
  19.         $this->query_str = $query_str;
  20.     }
  21. }

Step 2. Code the controller

Add the following code to your controller and existing mechanic for outputting the Grocery CRUD interface.

$crud = new grocery_CRUD();
$crud->set_model('custom_query_model');
$crud->set_table('employees'); //Change to your table name
$crud->basic_model->set_query_str('SELECT * FROM employees'); //Query text here
$output = $crud->render();


Paul Savostin
  • profile picture
  • Member

Posted 19 June 2015 - 21:31 PM

Hi! In abstraction way - lets say you have table "users" and "topics" which this users has wrtie.

 

To get topics by user you need simply controller with two methods:

1) method first - show user table

2)method second - show their topics

in 1) you set custom add_action link, where you get ID per user row. Next just by clicking this action you have ID as a parameter to another method 2, where you recieve ID -> set where('user_id', $user_id) and get records from "topics"

That's it.

 


shawn_gl
  • profile picture
  • Member

Posted 19 June 2015 - 23:27 PM

Thank you very much - that clarifies the approach that is great help


Paul Savostin
  • profile picture
  • Member

Posted 20 June 2015 - 00:34 AM

you're welcome!