0

I have to list regions in two areas in single view file. Top foreach loop is working but, below foreachloop is not working.

<div class="wiyo_reg"> <div class="wiyo_region_select span12"> Choose Destination </div> <div class="wiyo_region_option_holder"> <ul> <?php foreach($regions_list as $regions_list) { ?> <li class="wiyo_reg_li"> <a id="wiyo_reg_id" data-value="<?php echo $regions_list -> slug; ?>" data-image="<?php echo base_url(); ?>app/resources/wiyo/img/flags/<?php echo $regions_list -> code; ?>.png" data-txt="<?php echo $regions_list -> name; ?>"> <img src="<?php echo base_url(); ?>app/resources/wiyo/img/flags/<?php echo $regions_list -> code; ?>.png" /> <?php echo $regions_list -> slug; ?> </a> </li> <?php } ?> </ul> </div> <div class="destination_error"></div> </div> <?php echo form_open(base_url().'index.php/bookings/search', array('id' => 'booking_regions_form', 'class' => 'booking_regions_form')); ?> <select class="makefancy indexselect" name="booking_form_regions" style="display:none;"> <option value="0" selected="selected" data-skip="1">Choose Destination</option><?php foreach($regions_list as $regions) { ?> <option value="<?php echo $regions -> slug; ?>"><?php echo $regions -> name; ?></option> <?php } ?> </select> <div class="form_label_wi_input indexform"> <label>Departure Date</label> <input type="text" id="dpd6" name="booking_form_outbound_date" required="required" readonly="readonly" /> </div> <div class="form_label_wi_input indexform"> <label>Return Date</label> <input type="text" id="dpd7" name="booking_form_intbound_date" required="required" readonly="readonly" /> </div> <div class="form_label_wi_input"> <input type="submit" name="submit_region" id="submit_region" class="span5 btn btn-info" value="Book" /> </div> <?php echo form_close(); ?> 

I am getting list of regions in top foreach loop but, I am getting this type of error in below foreach loop.

<option value="<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> <h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Trying to get property of non-object</p> <p>Filename: partials/banner.php</p> <p>Line Number: 74</p> </div>"><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> <h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Trying to get property of non-object</p> <p>Filename: partials/banner.php</p> <p>Line Number: 74</p> </div></option> 
4
  • It looks like you are redefining your $regions_list in the foreach Commented Dec 20, 2013 at 16:05
  • 1
    this isnt an answer or anything but when using inline php like that you might want to take a look at alternate syntax for control stuctures php.net/alternative_syntax Commented Dec 20, 2013 at 16:07
  • I am not getting it properly. How would same foreach loop works once and then not. I am stuck. Helping hands are appreciated. I am running out of deadline. Commented Dec 20, 2013 at 16:19
  • I sent other array variable from the controller with same data and then it worked. I am not getting how these error occurs. Commented Dec 20, 2013 at 16:39

2 Answers 2

1

Try this, You have used to define $regions_list again in foreach loop $regions_list as $regions_list

foreach($regions_list as $region_list) 

instead of

 foreach($regions_list as $regions_list) 

Note: You need to replace $regions_list -> to $region_list -> in your code.

i.e. use <?php echo $region_list -> code; ?>

instead of <?php echo $regions_list -> code; ?>

Sign up to request clarification or add additional context in comments.

1 Comment

Did you replace the $region_list -> in all occurrence in your code
0

You reassign variable $regions_list to the same variable, try to use another variable like: $region_list
Try tho change your foreach like this:

<?php foreach($regions_list as $region_list){?> <li class="wiyo_reg_li"> <a id="wiyo_reg_id" data-value="<?php echo $region_list -> slug; ?>" data-image="<?php echo base_url(); ?>app/resources/wiyo/img/flags/<?php echo $region_list -> code; ?>.png" data-txt="<?php echo $region_list -> name; ?>"> <img src="<?php echo base_url(); ?>app/resources/wiyo/img/flags/<?php echo $region_list -> code; ?>.png" /> <?php echo $region_list -> slug; ?></a> </li> <?php } ?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.