Jump to content


dropdown without set_relation, but from different table

dropdown list table set_relation

  • Please log in to reply
11 replies to this topic

#1 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 02 April 2014 - 03:40 PM

How do I create a dropdown without having a relationship to a field. I can't use

 

$crud->set_relation.....

 

I do want to use something like this....

$crud->field_type('Field_Name','dropdown',
            array('1' => 'option_1', '2' => 'option_2,'3' => 'option_3 , '4' => 'option_4'));

but from a table, for example "tbl_Test" and create a list that is not related to any other fields.

 

Thank you for helping.

 

 



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 02 April 2014 - 06:26 PM

well you gave solution for yourself...

that is the way you have to do it.. what you need to do is select the entries / rows u want to put up into the dropdown and set it as array (key=>value) to the dropdown.



#3 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 02 April 2014 - 07:13 PM

$this -> db -> select('Field_Name');
$this -> db -> from('tbl_Name');
$query = $this -> db -> get();

foreach ($query->result() as $row)
                {
                    $array = $query->result_array();
                }
            
$crud->field_type('Field_Name2','dropdown', array('1' => 'abc', '2' => 'bcs','3' => 'fff' , '4' => 'rrrr'));

Sorry, still a beginner in PHP. How the first 4 lines look? If those work, what is the syntax to get the array in the last row of code. ...'dropdown', $array); ?



#4 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 02 April 2014 - 07:15 PM

It actually compiled. But I am getting a bunch of Array, Array, Array in the dropdown.



#5 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 02 April 2014 - 07:15 PM

$this -> db -> select('Carrier_SCAC');
         $this -> db -> from('carrier');
         $query = $this -> db -> get();

foreach ($query->result() as $row)
{
$array = $query->result_array();
}

$crud->field_type('TT_Carrier','dropdown', $array);

Little more help?



#6 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 02 April 2014 - 08:16 PM

Don't think you presenting the output in the required mechanism..

 

This should work .. likely.. didnt test but the code logically should work

$this -> db -> select('id, Carrier_SCAC');
         $this -> db -> from('carrier');
         $query = $this -> db -> get();
$finalArray = array();
foreach ($query->result() as $row)
{
	$finalArray[$row['id']]=$row['Carrier_SCAC'];
}

$crud->field_type('TT_Carrier','dropdown', $finalArray);


#7 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 02 April 2014 - 08:29 PM

$this -> db -> select('ID, Carrier_SCAC');
$this -> db -> from('carrier');
$query = $this -> db -> get();
$finalArray = array();
foreach ($query -> result() as $row)
{
//$finalArray[$row['ID']] = $row['Carrier_SCAC'];
$finalArray = $query->result_array();

}

$crud->field_type('TT_Carrier','dropdown', $finalArray);

 

 

It doesn't compile if I leave the commented section in there.



#8 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 04 April 2014 - 03:28 PM

Didn't understand the set_relation....solution

 

$crud->set_relation('TT_Carrier','users', 'Vendor',array('admin' => 'N'));



#9 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 05 April 2014 - 04:44 AM

What is the problem going with the set relation function .. 1st point..

 

secondly in yr code above... u using this - $finalArray = $query->result_array();

.....this is always going to give trouble.. cuz the output of that if u print in .. is going to be all the result sets for the query fired... in number of rows returned. so that 1 is never gona work out...



#10 Ron

Ron

    Member

  • Members
  • PipPip
  • 19 posts

Posted 07 April 2014 - 12:23 PM

I am using set_relation now.



#11 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 08 April 2014 - 11:56 AM

great.. happy to help you



#12 glopezr

glopezr

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 12 June 2015 - 09:39 AM

Thanks to all, as set_relation don't work when you use a table from other DB, I used this code to make the dropdown.
 
$crud = new grocery_CRUD();
$crud->set_table('testtable');
$crud->set_subject('TEST');

$crud->columns('id_sup',...............................................);

$DB1 = $this->load->database('otherdb', TRUE);

$query=$DB1->query("SELECT id, CONCAT (id,' - ',name) as fullname FROM supertabla WHERE activo=1 ORDER BY name ASC;");

$arr_ids = array();

foreach ($query->result() as $row)
{
    $arr_ids[$row->id]=$row->fullname;
}

$crud->field_type('id_sup','dropdown', $arr_ids);






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users