Welcome Guest, Not a member yet? Register   Sign In
Passing Query Results into Views Effeciently
#1

[eluser]Fielder[/eluser]
Am I running this query and passing the results into my view correct?

Code:
$data['results'] = $this->Businesses->getBusiness($bus_number);
                //load database query results into array for the input form
                foreach ($data['results'] as $row)
                {
                    $data['bus_name'] = $row['bus_name'];
                    $data['bus_number'] = $row['bus_number'];
                    $data['bus_address'] = $row['bus_address'];
                    $data['bus_city'] = $row['bus_city'];
                    $data['bus_state'] = $row['bus_state'];
                    $data['bus_zip'] = $row['bus_zip'];
                    $data['bus_contact'] = $row['bus_contact'];
                    $data['bus_phone'] = $row['bus_phone'];
                    $data['bus_mobile'] = $row['bus_mobile'];
                    $data['bus_fax'] = $row['bus_fax'];
                    $data['bus_email'] = $row['bus_email'];
                    $data['cat_id'] = $row['cat_id'];
                    $data['bus_corporate'] = $row['bus_corporate'];
                    $data['user_rep'] = $row['user_rep'];
                }
                
                
                $this->load->view('include/header.php', $data);
                $this->load->view('business_new',$data);

then in the view I'm inserting the individual variables into the "value" part of their corresponding input boxes...
Code:
<li>
                    <label for="bus_name">Business Name</label>
                    <em>*</em>&lt;input type="text" name="bus_name" size="36" value="&lt;?= $bus_name; ?&gt;" class="required" /&gt;
                </li>
                <li>
                    <label for="bus_number">Business Number</label>
                    <em>*</em>&lt;input type="text" name="bus_number" size="24" value="&lt;?= $bus_number; ?&gt;" class="required" /&gt;
                </li>
etc..
etc..
etc..

Seems that my foreach statement is looping through that entire array for every result returned from the model(I don't know). But I would like to know if I could improve upon this code to efficiently and with less typing pass and display the results in the input boxes. Thx.


Messages In This Thread
Passing Query Results into Views Effeciently - by El Forum - 04-26-2009, 02:33 AM
Passing Query Results into Views Effeciently - by El Forum - 04-26-2009, 04:55 AM
Passing Query Results into Views Effeciently - by El Forum - 04-26-2009, 05:08 AM
Passing Query Results into Views Effeciently - by El Forum - 04-26-2009, 10:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB