I have an Orders table that I’ve managed to display, but it takes ~25s to load. When the page loads, I want the table to have ~1000 entries. If the user wants to view older Orders, I will put a dropdown menu. When they select it, it will load the new set.
I tried putting a dropdown menu with the options, but couldn’t figure out how to pass that information inside the get_where
clause.
This is the code where I load the entire entries of the table order_id
is the orders id which I want to filter when it loads:
<code><span class="pln">$this</span><span class="pun">-></span><span class="pln">db</span><span class="pun">-></span><span class="pln">order_by</span><span class="pun">(</span><span class="str">"order_number"</span><span class="pun">,</span> <span class="str">"desc"</span><span class="pun">);</span><span class="pln"> $completed_orders </span><span class="pun">=</span><span class="pln"> $this</span><span class="pun">-></span><span class="pln">db</span><span class="pun">-></span><span class="pln">get_where</span><span class="pun">(</span><span class="str">'orders'</span> <span class="pun">,</span><span class="pln"> array</span><span class="pun">(</span><span class="str">'order_status'</span> <span class="pun">=></span><span class="str">'completed'</span><span class="pun">,</span><span class="str">'category'</span> <span class="pun">=></span> <span class="str">'mesoportes'</span><span class="pun">))-></span><span class="pln">result_array</span><span class="pun">();</span></code>
What i’m looking for is something like this
<code><span class="pln">$this</span><span class="pun">-></span><span class="pln">db</span><span class="pun">-></span><span class="pln">order_by</span><span class="pun">(</span><span class="str">"order_number"</span><span class="pun">,</span> <span class="str">"desc"</span><span class="pun">);</span><span class="pln"> $completed_orders </span><span class="pun">=</span><span class="pln"> $this</span><span class="pun">-></span><span class="pln">db</span><span class="pun">-></span><span class="pln">get_where</span><span class="pun">(</span><span class="str">'orders'</span> <span class="pun">,</span><span class="pln"> array</span><span class="pun">(</span><span class="str">'order_status'</span> <span class="pun">=></span><span class="str">'completed'</span><span class="pun">,</span> <span class="str">'category'</span> <span class="pun">=></span> <span class="str">'mesoportes'</span><span class="pun">,</span><span class="str">'order_id >'</span> <span class="pun">=></span><span class="pln"> $filter</span><span class="pun">))-></span><span class="pln">result_array</span><span class="pun">();</span></code>
where the filter at first run will be 8000 and if the user wants to view older orders then change it by selecting it in a dropdown menu
If you want to display old order by selecting dropdown value then you need to jQuery AJAX.
First, you have to pass a dropdown value another page or another function(where database values will select to match dropdown value), then fetch database values and return values.
Now return value display in the table by table id using jQuery append() of html() function. For example:
jQuery Ajax:
<script type="text/javascript"> $.ajax({ type: 'post', url: '<?php echo base_url("Controller/select_order_data");?>', data: {id:oder_id}, success: function(result){ console.log(result); jQuery('#OrderData').html(result); // #OrderData is the table tbody Id name!! // if you want to remove previous records the try it // jQuery('#OrderData').html(''); // jQuery('#OrderData').html(result); } }); </script>
Fetch Data:
<?php public function select_order_data(){ $GetData=$this->MyModel->selecOrderData(); $view = ''; foreach ($GetData as $data) { $view = $view ."<tr>"; $view = $view ."<td>".$data->order_name."</td>"; $view = $view ."<td>".$data->order_id."</td>"; $view = $view ."<td>".$data->order_price."</td>"; $view = $view ."</tr>"; } echo $view; } ?>
Select Data:
<?php public function selecOrderData(){ $qry=$this->db->select('*')->from('Table Name')->where('order_id',$id)->get()->result(); return $qry; } ?>
Please comment here, if you need to more help.