title: Issue in table sorting inside expandable table in codeigniter
body: <p>I want to sort my table data in expandable table view, so I tried the below code: </p>
  
  <p><a href="https://github.com/joequery/Stupid-Table-Plugin" rel="nofollow noreferrer">Code Link</a></p>
  
  <p>and my view is as in the below image
  <img src="https://i.stack.imgur.com/0tkNI.png" alt="enter image description here"></p>
  
  <p>When I use this code and put in my site, it is not working in this type of view like expandable table view. The sorting is not being performed in the expandable table view. Any idea how can I make it work?</p>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p><strong>stupidtable.js</strong></p>
  
  <pre><code>// Stupid jQuery table plugin.
  
   (function($) {
   $.fn.stupidtable = function(sortFns) {
   return this.each(function() {
    var $table = $(this);
    sortFns = sortFns || {};
    sortFns = $.extend({}, $.fn.stupidtable.default_sort_fns, sortFns);
    $table.data('sortFns', sortFns);
  
    $table.on("click.stupidtable", "thead th", function() {
        $(this).stupidsort();
     });
    });
  };
  
  
   // Expects $("#mytable").stupidtable() to have already been called.
   // Call on a table header.
   $.fn.stupidsort = function(force_direction){
   var $this_th = $(this);
   var th_index = 0; // we'll increment this soon
   var dir = $.fn.stupidtable.dir;
   var $table = $this_th.closest("table");
   var datatype = $this_th.data("sort") || null;
  
   // No datatype? Nothing to do.
   if (datatype === null) {
    return;
   }
  
  // Account for colspans
  $this_th.parents("tr").find("th").slice(0, $(this).index()).each(function()       {
    var cols = $(this).attr("colspan") || 1;
    th_index += parseInt(cols,10);
  });
  
  var sort_dir;
  if(arguments.length == 1){
      sort_dir = force_direction;
  }
  else{
      sort_dir = force_direction || $this_th.data("sort-default") || dir.ASC;
      if ($this_th.data("sort-dir"))
         sort_dir = $this_th.data("sort-dir") === dir.ASC ? dir.DESC : dir.ASC;
  }
  
  
  $table.trigger("beforetablesort", {column: th_index, direction: sort_dir});
  
  // More reliable method of forcing a redraw
  $table.css("display");
  
  // Run sorting asynchronously on a timout to force browser redraw after
  // `beforetablesort` callback. Also avoids locking up the browser too much.
  setTimeout(function() {
    // Gather the elements for this column
    var column = [];
    var sortFns = $table.data('sortFns');
    var sortMethod = sortFns[datatype];
    var trs = $table.children("tbody").children("tr");
  
    // Extract the data for the column that needs to be sorted and pair it up
    // with the TR itself into a tuple. This way sorting the values will
    // incidentally sort the trs.
    trs.each(function(index,tr) {
      var $e = $(tr).children().eq(th_index);
      var sort_val = $e.data("sort-value");
  
      // Store and read from the .data cache for display text only sorts
      // instead of looking through the DOM every time
      if(typeof(sort_val) === "undefined"){
        var txt = $e.text();
        $e.data('sort-value', txt);
        sort_val = txt;
      }
      column.push([sort_val, tr]);
    });
  
    // Sort by the data-order-by value
    column.sort(function(a, b) { return sortMethod(a[0], b[0]); });
    if (sort_dir != dir.ASC)
      column.reverse();
  
    // Replace the content of tbody with the sorted rows. Strangely
    // enough, .append accomplishes this for us.
    trs = $.map(column, function(kv) { return kv[1]; });
    $table.children("tbody").append(trs);
  
    // Reset siblings
    $table.find("th").data("sort-dir", null).removeClass("sorting-desc sorting-asc");
    $this_th.data("sort-dir", sort_dir).addClass("sorting-"+sort_dir);
  
    $table.trigger("aftertablesort", {column: th_index, direction: sort_dir});
    $table.css("display");
  }, 10);
  
  return $this_th;
   };
  
    // Call on a sortable td to update its value in the sort. This should be the
    // only mechanism used to update a cell's sort value. If your display value is
   // different from your sort value, use jQuery's .text() or .html() to update
   // the td contents, Assumes stupidtable has already been called for the table.
   $.fn.updateSortVal = function(new_sort_val){
   var $this_td = $(this);
   if($this_td.is('[data-sort-value]')){
    // For visual consistency with the .data cache
    $this_td.attr('data-sort-value', new_sort_val);
    }
   $this_td.data("sort-value", new_sort_val);
   return $this_td;
  };
  
   // ------------------------------------------------------------------
    // Default settings
   // ------------------------------------------------------------------
   $.fn.stupidtable.dir = {ASC: "asc", DESC: "desc"};
   $.fn.stupidtable.default_sort_fns = {
  "int": function(a, b) {
    return parseInt(a, 10) - parseInt(b, 10);
  },
  "float": function(a, b) {
    return parseFloat(a) - parseFloat(b);
  },
   "string": function(a, b) {
    return a.localeCompare(b);
  }, 
  "string-ins": function(a, b) {
    a = a.toLocaleLowerCase();
    b = b.toLocaleLowerCase();
    return a.localeCompare(b);
   }
   };
   })(jQuery);
  </code></pre>
  
  <p><strong>my Script code</strong></p>
  
  <pre><code> &lt;script&gt;
  $(function(){
      // Helper function to convert a string of the form "Mar 15, 1987" into a Date object.
      var date_from_string = function(str) {
        var months = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"];
        var pattern = "^([a-zA-Z]{3})\\s*(\\d{1,2}),\\s*(\\d{4})$";
        var re = new RegExp(pattern);
        var DateParts = re.exec(str).slice(1);
  
        var Year = DateParts[2];
        var Month = $.inArray(DateParts[0].toLowerCase(), months);
        var Day = DateParts[1];
  
        return new Date(Year, Month, Day);
      }
  
      var table = $("table").stupidtable({
        "date": function(a,b) {
          // Get these into date objects for comparison.
          aDate = date_from_string(angel);
          bDate = date_from_string(beer);
          return aDate - bDate;
        }
      });
  
      table.on("beforetablesort", function (event, data) {
        // Apply a "disabled" look to the table while sorting.
        // Using addClass for "testing" as it takes slightly longer to render.
        $("#msg").text("Sorting...");
        $("table").addClass("disabled");
      });
  
      table.on("aftertablesort", function (event, data) {
        // Reset loading message.
        $("#msg").html("&amp;nbsp;");
        $("table").removeClass("disabled");
  
        var th = $(this).find("th");
        th.find(".arrow").remove();
        var dir = $.fn.stupidtable.dir;
  
        var arrow = data.direction === dir.ASC ? "&amp;uarr;" : "&amp;darr;";
        th.eq(data.column).append('&lt;span class="arrow"&gt;' + arrow +'&lt;/span&gt;');
      });
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>When I run the above code and expand my view, in my <strong>stupidtable.js</strong> file there is code like </p>
  
  <pre><code>"string": function(a, b) {
    return a.localeCompare(b);
  },  
  </code></pre>
  
  <p>In this code <code>a.localeCompare(b);</code> is getting null in expandable table view so it is not sorting well, and I also want sorting inside the data which table is expanded. Any idea how I can solve this issue?</p>
  
  <p><strong>html code</strong></p>
  
  <pre><code>&lt;table id="property" class="hometable table-bordered"&gt;
                        &lt;thead&gt;
                          &lt;tr&gt;
                            &lt;th &gt;#&lt;/th&gt;
                            &lt;th  &gt;Image&lt;/th&gt;
                            &lt;th width="12%" &gt;
                              &lt;a href="&lt;?php echo base_url();?&gt;property/propertylist?field=p_name&amp;sort_by=&lt;?php echo $sort;?&gt;"&gt;
                                Property Name &amp;nbsp;
                                &lt;? if($sort == 'ASC' &amp;&amp; $_GET['field']=='p_name') echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'&gt;'; else if($sort == 'DESC'&amp;&amp; $_GET['field']=='p_name') { echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'&gt;';  } else {echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'&gt;';}?&gt;
                              &lt;/a&gt;
                            &lt;/th&gt;
                            &lt;th &gt;Address&lt;/th&gt;
                            &lt;th &gt;
                              &lt;a href="&lt;?php echo base_url();?&gt;property/propertylist?field=p_city&amp;sort_by=&lt;?php echo $sort;?&gt;"&gt;
                                City &amp;nbsp;
                                &lt;? if($sort == 'ASC' &amp;&amp; $_GET['field']=='p_city') echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'&gt;'; else if($sort == 'DESC' &amp;&amp; $_GET['field']=='p_city') { echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'&gt;';  } else {echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'&gt;';}?&gt;
                              &lt;/a&gt;
                            &lt;/th&gt;
                            &lt;th &gt;
                              &lt;a href="&lt;?php echo base_url();?&gt;property/propertylist?field=p_state&amp;sort_by=&lt;?php echo $sort;?&gt;"&gt;
                                State &amp;nbsp;
                                &lt;? if($sort == 'ASC' &amp;&amp; $_GET['field']=='p_state') echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'&gt;'; else if($sort == 'DESC' &amp;&amp; $_GET['field']=='p_state') { echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'&gt;';  } else {echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'&gt;';}?&gt;
                              &lt;/a&gt;
                            &lt;/th&gt;
                            &lt;th width="9%" &gt;
                              &lt;a href="&lt;?php echo base_url();?&gt;property/propertylist?field=p_country&amp;sort_by=&lt;?php echo $sort;?&gt;"&gt;
                                Country &amp;nbsp;
                                &lt;? if($sort == 'ASC' &amp;&amp; $_GET['field']=='p_country') echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'&gt;'; else if($sort == 'DESC' &amp;&amp; $_GET['field']=='p_country') { echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'&gt;';  } else {echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'&gt;';}?&gt;
                              &lt;/a&gt;
                            &lt;/th&gt;
                            &lt;th &gt;Zipcode&lt;/th&gt;
                            &lt;th colspan="2" &gt;
                              &lt;a href="&lt;?php echo base_url();?&gt;property/propertylist?field=unit_type&amp;sort_by=&lt;?php echo $sort;?&gt;"&gt;
                                Property Type &amp;nbsp;
                                &lt;? if($sort == 'ASC' &amp;&amp; $_GET['field']=='unit_type') echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'&gt;'; else if($sort == 'DESC' &amp;&amp; $_GET['field']=='unit_type') { echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'&gt;';  } else {echo '&lt;img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'&gt;';}?&gt;
                              &lt;/a&gt;
                            &lt;/th&gt;
                            &lt;th &gt;Tenants&lt;/th&gt;
                            &lt;? if(!empty($query1)){?&gt;
                            &lt;th &gt;Edit &lt;/th&gt;
                            &lt;th &gt;Copy &lt;/th&gt;
                            &lt;th &gt;Delete &lt;/th&gt;
                            &lt;? } else {?&gt;
                            &lt;th &gt;Edit &lt;/th&gt;
                            &lt;th &gt;Copy&lt;/th&gt;
                            &lt;th &gt;Delete&lt;/th&gt;
                            &lt;? } ?&gt;
                          &lt;/tr&gt;
                        &lt;/thead&gt;
                        &lt;?  if(empty($detail)) {  ?&gt;
                        &lt;tr&gt;
                          &lt;td colspan="14"&gt;
                            &lt;div class="tblalert alert-danger"&gt;&lt;!--&lt;button class="close" data-close="alert"&gt;&lt;/button&gt;--&gt;&lt;span&gt;No property available.&lt;/span&gt;&lt;/div&gt;
                          &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;?php }else {
              $i = 0;
              foreach($detail as $pro) {  
  
                      $i++;
          ?&gt;
                        &lt;tr id="trarrow&lt;? echo $i;?&gt;"&gt;
                          &lt;? $admindata = $this-&gt;session-&gt;userdata('id');
       $query = $this-&gt;db-&gt;query('SELECT r_country,amt_format FROM register where id="'.$admindata.'"');
                foreach ($query-&gt;result() as $row)
                {     $currency = $row-&gt;r_country ;
                      $amt_format = $row-&gt;amt_format ;
                }
                 $curren = $this-&gt;db-&gt;query('SELECT * FROM country where id="'.$currency.'"');
                foreach ($curren-&gt;result() as $row)
                {     $curr = $row-&gt;currency ;
  
                }
  
                $unit = $this-&gt;db-&gt;query("SELECT * FROM property_unit WHERE p_id = '".$pro['p_id']."'");
                $unitid = count($unit-&gt;result_array());
         ?&gt;
                          &lt;?php /*?&gt;&lt;?php if($pro['unit_type'] == '0'){ ?&gt;
         &lt;td align="center"   style="cursor:pointer"&gt;&lt;div class="arrow" id="arimg&lt;?php  echo $i?&gt;"&gt;&lt;/div&gt;&lt;/td&gt;
         &lt;? } else {?&gt;
                       &lt;td align="center" id="arrow&lt;?php  echo $i?&gt;" onClick="trshow(&lt;?php  echo $i?&gt;);" style="cursor:pointer"&gt;&lt;div class="arrow" id="arimg&lt;?php  echo $i?&gt;"&gt;&lt;/div&gt;&lt;/td&gt;
  
           &lt;? } ?&gt;&lt;?php */?&gt;
                          &lt;td&gt;&lt;?php echo $i; ?&gt;&lt;/td&gt;
                          &lt;td align="center"&gt;
                            &lt;?  if(!empty($pro['p_path'])) {  ?&gt;
                            &lt;a class="fancybox fancyboxiframe" href="&lt;?php echo base_url('property/popup/'.$pro['p_id']);?&gt;"&gt;
                              &lt;img class="img-polaroid" src="http://worldofrental.s3.amazonaws.com/&lt;? echo $pro['p_path'];?&gt;" alt="Please Upload Image" width="50" height="50"&gt;
                              &lt;? } else {?&gt;
                              &lt;img class="img-polaroid" src=&lt;? echo base_url('upload/tenants/app_logo.png');?&gt; alt="Upload Image" width="50" height="50"&gt;
                              &lt;? } 
  
  
                 ?&gt;
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;td &gt;
                            &lt;a href="&lt;? echo base_url('property/propertyedit/'.$pro['p_id']);?&gt;"&gt;
                              &lt;?php echo $pro['p_name']; ?&gt;
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;td &gt;&lt;?php echo $pro['p_address']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $pro['p_city']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;
                            &lt;?php $statename =  $this-&gt;db-&gt;query("SELECT state_name FROM state WHERE state_id = '".$pro['p_state']."'"); $state_name = $statename-&gt;result_array(); echo $state_name[0]['state_name']; ?&gt;
                          &lt;/td&gt;
                          &lt;td &gt;&lt;?php echo $pro['name']; ?&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;?php echo $pro['p_zipcode']; ?&gt;&lt;/td&gt;
                          &lt;?php if($pro['unit_type'] == '0'){ ?&gt;
                          &lt;td style="border-right:solid 0px !important; "&gt;&lt;/td&gt;
                          &lt;td align="right" style="border-left:solid 0px !important; "&gt;&lt;?php echo 'Single Unit'; ?&gt;&lt;/td&gt;
                          &lt;? } else {?&gt;
                          &lt;td style="border-right:solid 0px !important; cursor:pointer; " id="arrow&lt;?php  echo $i?&gt;" onClick="trshow(&lt;?php  echo $i?&gt;);" &gt;
                            &lt;div class="arrow" id="arimg&lt;?php  echo $i?&gt;"&gt;&lt;/div&gt;
                          &lt;/td&gt;
                          &lt;td align="right" style="cursor:pointer; border-left:solid 0px !important; " id="arrow&lt;?php  echo $i?&gt;" onClick="trshow(&lt;?php  echo $i?&gt;);" &gt;
                            &lt;div id="arimg&lt;?php  echo $i?&gt;"&gt;&lt;/div&gt;
                            &lt;a class="btn default btn-xs blue" &gt;
                              &lt;? echo 'Multi Unit' .'&amp;nbsp;'.'('.$unitid.')';?&gt;
                            &lt;/a&gt;
                            &lt;? } ?&gt;
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                            &lt;a class="btn default btn-xs yellow" data-toggle="modal" onClick="Viewtenants(&lt;? echo $pro['p_id'];?&gt;); return false;" title="View Tenants" href="#myproperty-&lt;? echo $pro['p_id'];?&gt;"&gt;
                              View Tenants
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;div id="myproperty-&lt;? echo $pro['p_id'];?&gt;" class="modal fade"&gt;&lt;/div&gt;
                          &lt;? if(!empty($query1)){?&gt;
                          &lt;td&gt;
                            &lt;a class="btn blue disabled" title="your service has been canceled" href="&lt;?php echo base_url('property/propertyedit/'.$pro['p_id']);?&gt;"&gt;
                              &lt;i class="fa fa-edit"&gt;&lt;/i&gt; Edit
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;div id="myModal-&lt;? //echo $pro-&gt;pid;?&gt;" class="modal fade"&gt;&lt;/div&gt;
                          &lt;td&gt;
                            &lt;a class="btn green disabled" title="your service has been canceled" href="&lt;?php echo base_url('property/copydata/'.$pro['p_id']);?&gt;"&gt;
                              &lt;i class="fa fa-copy"&gt;&lt;/i&gt; Copy
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;!--&lt;td class="status" align="center"&gt;&lt;a style="cursor:pointer" title="Trash" onClick="CheckUsername(&lt;? echo $pro['p_id'];?&gt;); return false;" id="status"&gt;
                &lt;div id="status-&lt;? echo $pro['p_id'];?&gt;"&gt; 
                                  &lt;/div&gt;  &lt;i class="fa fa-trash-o"&gt;&lt;/i&gt; Trash&lt;/a&gt;&lt;/td&gt;--&gt;
                          &lt;td&gt;
                            &lt;a class="delete btn red disabled btn-xs black delete-confirm" delete-url="&lt;?php echo base_url('property/status_change/'.$pro['p_id']);?&gt;" data-confirm="Are you sure you want to trash this property?" title="your service has been canceled"&gt;
                              &lt;i class="fa fa-trash-o"&gt;&lt;/i&gt; Delete
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;? } else {?&gt;
                          &lt;td&gt;
                            &lt;a  class="btn default btn-xs blue" title="Edit/View" href="&lt;?php echo base_url('property/propertyedit/'.$pro['p_id']);?&gt;"&gt;
                              &lt;i class="fa fa-edit"&gt;&lt;/i&gt; Edit
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;div id="myModal-&lt;? //echo $pro-&gt;pid;?&gt;" class="modal fade"&gt;&lt;/div&gt;
                          &lt;td align="center"&gt;
                            &lt;a class="btn default btn-xs green" title="Edit/View" href="&lt;?php echo base_url('property/copydata/'.$pro['p_id']);?&gt;"&gt;
                              &lt;i class="fa fa-copy"&gt;&lt;/i&gt; Copy
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                            &lt;a class="btn red" data-toggle="modal" onClick="ViewStore(&lt;? echo $pro['p_id'];?&gt;); return false;" title="Delete" href="#myModal-&lt;? echo $pro['p_id'];?&gt;"&gt;
                              &lt;i class="fa fa-trash-o"&gt;&lt;/i&gt;
                              &lt;font size="-1"&gt; Delete&lt;/font&gt;
                            &lt;/a&gt;
                          &lt;/td&gt;
                          &lt;div id="myModal-&lt;? echo $pro['p_id'];?&gt;" class="modal fade"&gt;&lt;/div&gt;
                          &lt;? } ?&gt;
                        &lt;/tr&gt;
                        &lt;tr id="subtr&lt;?php echo $i; ?&gt;"&gt;
                          &lt;td colspan="14"&gt;
                            &lt;? $unit_info = $this-&gt;db-&gt;query("SELECT * FROM unit_info WHERE p_id = '".$pro['p_id']."' AND isactive = '0' AND unit_id &lt;&gt; '0'");
                              $result = $unit_info-&gt;result_array();
                              ?&gt;
                            &lt;? if(empty($result)) {?&gt;
                            &lt;? }else{ ?&gt;
                            &lt;div class="propertyreport-box"&gt;
                              &lt;div class="title"&gt;Property Units&lt;/div&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Unit Name&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;? $unitname = $this-&gt;db-&gt;query("SELECT unit_name FROM property_unit WHERE unit_id = '".$unit-&gt;unit_id."'"); $unit_name = $unitname-&gt;result_array();   echo $unit_name[0]['unit_name'] ;?&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Rent &lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;? if(!empty($unit-&gt;p_rent)){ echo $curr.' '.$unit-&gt;p_rent;}else { echo $curr.' '.'0.00';}?&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Bedrooms&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;? if(!empty($unit-&gt;p_bedroom)){ echo $unit-&gt;p_bedroom; }else { echo '0.0';}?&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Bathrooms&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;? if(!empty($unit-&gt;p_bathroom)){ echo $unit-&gt;p_bathroom; }else { echo '0.0';}?&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Sq. Ft&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;? if(!empty($unit-&gt;p_size)){ echo $unit-&gt;p_size; }else { echo '0.00';}?&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Rented&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;&lt;? echo $unit-&gt;p_isrent;?&gt;&lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Tenants&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;a class="btn btn-xs yellow" data-toggle="modal" onClick="viewunittenants(&lt;? echo $unit-&gt;unit_info_id;?&gt;); return false;" title="Delete" href="#myproperty-&lt;? echo $unit-&gt;unit_info_id;?&gt;"&gt;
                                    &lt;font size="-2"&gt; View Tenants&lt;/font&gt;
                                  &lt;/a&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;div id="myproperty-&lt;? echo $unit-&gt;unit_info_id;?&gt;" class="modal fade "&gt;&lt;/div&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Edit&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;a class="btn btn-xs yellow" title="Edit/View" href="&lt;?php echo base_url('unit/unitedit/'.$unit-&gt;unit_info_id);?&gt;"&gt;
                                    &lt;i class="fa fa-edit"&gt;&lt;/i&gt;
                                    &lt;font size="-2"&gt; Edit&lt;/font&gt;
                                  &lt;/a&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                              &lt;ul class="finacial-list"&gt;
                                &lt;li&gt;&lt;strong&gt;Delete&lt;/strong&gt;&lt;/li&gt;
                                &lt;? foreach($unit_info-&gt;result() as $unit){?&gt;
                                &lt;li&gt;&lt;span&gt;
                                  &lt;a class="btn btn-xs dark" data-toggle="modal" onClick="ViewStore1(&lt;? echo $unit-&gt;unit_info_id;?&gt;); return false;" title="Delete" href="#myModal1-&lt;? echo $unit-&gt;unit_info_id;?&gt;"&gt;
                                    &lt;i class="fa fa-trash-o"&gt;&lt;/i&gt;
                                    &lt;font size="-2"&gt; Delete&lt;/font&gt;
                                  &lt;/a&gt;
                                  &lt;/span&gt;&lt;/li&gt;
                                &lt;div id="myModal1-&lt;? echo $unit-&gt;unit_info_id;?&gt;" class="modal fade "&gt;&lt;/div&gt;
                                &lt;? } ?&gt;
                              &lt;/ul&gt;
                            &lt;/div&gt;
                            &lt;? } ?&gt;
                          &lt;/td&gt;
                        &lt;/tr&gt;
                        &lt;?php
  } }
  ?&gt;
                      &lt;/table&gt;
  </code></pre>