php - Codeigniter - Is it possible to add multiple dynamic datas to view

Solution:
It's not hard to send lots of data to a view. The thing to understand is how the array you send to the view is used. Put simply, eachkey
in the array will be the name of avariable
in the view. The array must be an associative array.
With that in mind
//this line
$getPlacetype = $this->Placetype->getPlacetype();
// should be changed to this
$view_data['getPlacetype'] = $this->Placetype->getPlacetype();
and then
$custom_errors["nadate"] = ($this->verifydate($_POST["startdate"],
// changed to
$nadate = ($this->verifydate($_POST["startdate"],
$_POST["enddate"]) < 3 ? false : true);
You can delete the line
$custom_errors["nadate"] = false;
Change this
if($this->form_validation->run() == TRUE &&
$this->verifydate($_POST["startdate"], $_POST["enddate"]) < 3) {
to
if($nadate === TRUE && $this->form_validation->run() === TRUE) {
If the above block is not executed then create an error message and load the view
$view_data['custom_errors'] = "Start and End dates were wrong";
$this->load->view('profile', $view_data);
The relevant part of the view could be done like this.
<div class="form-group">
<label for="place_type">City/Province</label>
<select name="place_type">
<option value="place_type">-Please Select One-</option>
<?php
if(count($getPlacetype)) :
foreach ($getPlacetype as $getplacetype):
?>
<option value=<?php echo $getplacetype->place_id; ?>>
<?php
echo $getplacetype->place_type;
echo $getplacetype->place_price;
?>
<span> PHP Shipping Fee</span>
</option>
<?php
endforeach;
else:
echo isset($custom_errors) ? $custom_errors : NULL;
endif;
?>
</select>
</div>
Hope this demonstrates how to do what you want.
Answer
Solution:
try this:define array blank.
public function index(){
$data = array();
//here you can use $data and like firstArray you can pass in your view page.you can use multiple array like this and pass then in view.
$data['firstArray']=get data;
$data['secondArray']=get data;
$this->load->view(''profile', $data);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object of class stdclass could not be converted to string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.