Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeIgniter Getting the result of a query as a text input value
    primarykey
    data
    text
    <p>I wrote a small piece to get a value from a database table according to the input user provides. Quickly here are the events:</p> <ol> <li>User inputs number to an input and submit form</li> <li>That data are supposed to call the controller, and then the controller have to match and grab relevant data from the database table, and pass it to the controller again.</li> <li>Then the controller must pass it to the view, where another text input (readonly) picks up the data as the value.</li> </ol> <p>But what I received was an error:</p> <p>Message: Undefined variable: due_amount Filename: main/new_payment.php Line Number: 148</p> <p>Line number 148 in new_payment.php is</p> <pre><code>); </code></pre> <p>in the View.</p> <p>This is my <strong>Model</strong>:</p> <pre><code>function get_by_room_number($room_data) { $this-&gt;db-&gt;select('due_amount'); $query = $this-&gt;db-&gt;get_where('rooms', array('room_number' =&gt; $room_data), 1); if($query-&gt;num_rows()&gt;0) { foreach ($query-&gt;result() as $row) { return $row-&gt;due_amount; } } </code></pre> <p>This is the <strong>Controller</strong>:</p> <pre><code>function search_by_number() { $room_data = $this-&gt;input-&gt;post('room_number'); $due_amount = $this-&gt;payments_model-&gt;get_by_room_number($room_data); $this-&gt;index(); } </code></pre> <p>This is the <strong>View</strong>: (new_payment.php)</p> <pre><code>&lt;?php echo form_open('payments/search_by_number'); ?&gt; &lt;?php $data = array( 'name' =&gt; 'total_amount', 'id' =&gt; 'appendedPrependedInput', 'class' =&gt; 'span2', 'value' =&gt; $due_amount ); // Line Number 148 echo form_input($data); ?&gt; &lt;?php echo form_close(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload