Welcome Guest, Not a member yet? Register   Sign In
How to Sorting my Tables Fields?
#1

[eluser]Jauhari[/eluser]
I am newbie in CI and I really enjoy with this framework.

I have question about how to sort or add where condition.
This is my detail problem.

I was made some tabular data with some field, example name and email. then I was succesfully display my tabular data on my view.

My Question is, how to sorting my data? on my tables I have some date added. And I want make simple form, where I can input some value (example input data added on 2/2/2008 only) and my tabular data automatically will change to current data on 2/2/2008 only.

How to do that? please help me.

I was try add this code on my controllers
Code:
function address() {
    
        $this->load->helper('form');    
        $this->db->select('nama,email,date');
        $this->db->where('date','$date');        
        $this->db->from('address');
        $data['query'] = $this->db->get();
        
        $this->load->view('address', $data);
        }

And code on my Views
Code:
<form action="" method="POST">
        <?php
        $datas = array(
              'name'        => 'date',
              'id'          => 'date',
              'value'       => '8',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'yellow',
            );

$date = form_input($datas);
echo $date;
        ?>

                <button type="submit" class="button positive">
          Submit
                </button>
        &lt;/form&gt;

<table class="data">
<tr class="head">
    <th id="nid" rowspan="2" scope="col">No.</th>
    <th id="nper" rowspan="2" scope="col">Name</th>
    <th rowspan="2" scope="col">Email</th>
</tr>


&lt;?php
$i = 1;
if ($query->num_rows() > 0):
    foreach ($query->result() as $row):
?&gt;
<tr class="&lt;?php if($i%2 == '0'): echo "alt"; else: echo "row"; endif; ?&gt;">
    <td class="td-center">&lt;?php echo $i;$i++;?&gt;</td>
    <td class="td-center">&lt;?php echo $row->name;?&gt;</td>
    <td class="td-center">&lt;?php echo $row->email; ?&gt;</td>
</tr>
&lt;?php
    endforeach;
endif;
?&gt;    
</table>

But my sorting doesn't work Sad

Please Help Me
#2

[eluser]ontguy[/eluser]
You could use order to sort by date, for the initial sort
$this->db->order_by('date');

A javascript sort could be done: http://madhatted.com/2008/1/16/the-joy-o...table-sort

You could use ajax to refresh the table with the current row in a input field, then the full table when the text is removed, here are a couple examples :
http://www.phatfusion.net/sortabletable/index.htm
http://ideamill.synaptrixgroup.com/jquer...letest.htm
#3

[eluser]Jauhari[/eluser]
Hi OntGuy

That I need to do is make limitations on some dates only. So I have some form with some input field and I can input some date and when I click submit, the list will be show up data on my current date

How to do that?

Thanks
#4

[eluser]Avatar[/eluser]
you may need to call a separate query like so:
Code:
$q=$this->db->query('select * from `table` where `date`="'.$date.'"');
or like a previous suggestion was made to use javascript on currently pulled data




Theme © iAndrew 2016 - Forum software by © MyBB