Welcome Guest, Not a member yet? Register   Sign In
CI/jQuery
#1

[eluser]beasten[/eluser]
Hi all,

Im new here and at CodeIgniter. Im doin a little project and ran into som problems. Donno if this question is OK with you, it contains a little bit of jQuery too.

I have a jQuery list (not really important if its jQ or not..) with "expenses", when I click one of my expenses theres a little dropdown-form (jQuery) with the values of my expense. (Its an economy project)

My question is how do I get the value from my expense to be filled in to my form so that I can edit the expense? Ive tried the urisegment, tho I dont get it to work. Code Below.

Thank you, Beasten

Code:
<div id="top10">
                <ul>
                    &lt;?
                    $this->load->database();
                    $user_id = $this->session->userdata('USERID');
                    $query = mysql_query("SELECT * FROM EXPENSES WHERE USERID =     $user_id ORDER BY DATE DESC LIMIT 10");
                        while ($result = mysql_fetch_array($query)) {
                            echo ("<li><a href='$result[0]/#editField'>$result[2]
                                  $result[3],-</a></li>");
                        }
                    ?&gt;
                </ul>
            </div>
          
            <div id="editField">
            &lt;form&gt;
              
                &lt;input name="edit" type="text" value="&lt;? echo $this-&gt;uri->segment(4); ?&gt;">
                &lt;input type="submit" value="Change"&gt;
            &lt;/form&gt;
            </div>
#2

[eluser]Thorpe Obazee[/eluser]
i didn't read the problem or some of the code well. I have one comment though. Why are you loading the database class in the view?
#3

[eluser]beasten[/eluser]
Thats a mistake, missed it. ( beginner at this Wink )
#4

[eluser]beasten[/eluser]
Is there some other way than with urisegment?
#5

[eluser]Dam1an[/eluser]
You could have them passed into the controller as variables, and then pass them into the view
#6

[eluser]beasten[/eluser]
How do I pass them into the controller?
#7

[eluser]Dam1an[/eluser]
Its in the user guide Smile
#8

[eluser]boony[/eluser]
Hi,

I'm not sure if I understand your problem, but if you want to populate a drop down box with values from your database this should work.

You should have a model, and in that model a function like this:
Code:
function drop_down_data()
    {
        $data = array();
        $this->db->select('your_field'); //Put your field name here
        $this->db->from('your_table'); //Put your table here
        $query = $this->db->get();
        foreach($query->result_array() as $row)
        {
            $data[$row['your_field']] = $row['your_field'];
        }
        return $data;
    }

Now in your controller you should have something like this:

Code:
function get_drop_down_data()
    {
        $data['somestuff'] = $this->your_model->drop_down_data();
        $this->load->view('your_view', $data);
    }

And in your view, make the form *NOTE* that I'm using the form helper here (have a look in the user guide) and you will need to do all the other stuff. But this will now give you a select with your values.

Code:
echo '<p>'. form_label('Some Name','your_field');
    echo form_dropdown('your_field', $somestuff) .'</p>';




Theme © iAndrew 2016 - Forum software by © MyBB