Part of the EllisLab Network
   
 
Newbe question
Posted: 10 April 2006 01:13 PM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  117
Joined  03-29-2006

Hi there,

I want to use a database output in a dropdown box but can’t do the magic with array’s.
how dos that work?

I have this in the controler:


$sql = “SELECT inst_id, inst_rument”
. “\nFROM instr”
. “\nORDER BY inst_rument”;
$query = $this->db->query($sql);


// DATA ARRAY
$data = array(

// laden queries,
‘query’=>  $query
);

$this->load->view(‘page’, $data);
</php>

And this code to load the array in de view file

<? echo form_dropdown(‘instrumenten’, $query); ?>

and i used:

<? echo form_dropdown(‘instrumenten’, $query->result_array()); ?>

I get the dropdown list but only showing array or object.

How to do this?

thanks!

Profile
 
 
Posted: 10 April 2006 02:11 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  547
Joined  03-08-2006

To begin with, I don’t think you need those \n characters in your SQL query - just have it all on one line. Next, you need to supply the results to the view (not the query) using result_array() as detailed on this page in the User Guide. Your code should then look like this:

$sql = "SELECT inst_id, inst_rument FROM instr ORDER BY inst_rument";
$query = $this->db->query($sql);
$result = $query->result_array();

$data = array(
'query'=>$result
);

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

Twitter | Flickr | Last.fm | Del.icio.us

Profile
 
 
Posted: 10 April 2006 02:25 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  117
Joined  03-29-2006

Yes i tried that…

and now again but that dosn’t work either.
i dont get results that way.

Now i just don’t use the form helper but i would like to kno how to use it.

Thank though.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120200 Total Logged-in Users: 67
Total Topics: 126330 Total Anonymous Users: 4
Total Replies: 664385 Total Guests: 548
Total Posts: 790715    
Members ( View Memberlist )