Hi Can any one help me how to to get the records in between the dates by using from and to dates using php,mysql,ajax

Recommended Answers

All 4 Replies

Member Avatar for diafol

Yes if you show your code. You don't give any info.

Have a think about what you're actually asking for and read this: http://bit.ly/Dwebphp

Actually if i search by using the date iam not getting the data on that day iam getting all the records which are not on that date also.

$datefrom1 = $this->input->post('datefrom');
        $dateto1 =  $this->input->post('dateto');
        if($datefrom1 != '' && $dateto1 != '')
        {
            $datefrom=date("Y-m-d",strtotime($datefrom1));
            $dateto=date("Y-m-d",strtotime($dateto1));
        }
        else
        {
            $datefrom=$datefrom1;
            $dateto=$dateto1;
        }

        $this->db->select('invoice_master.*,D.category_name,C.customer_name');      
        $this->db->from('invoice_master');      
        $this->db->join('customer_details AS C','C.customer_id=invoice_master.customer_id','INNER');
        $this->db->join('department_category AS D','D.category_id=invoice_master.category_id','INNER');
        $this->db->like('invoice_master.date',$this->input->post('invoice_id'));
        $datecondition;

This is my Query which iam using for getting the records by using from and to dates.

Member Avatar for diafol

Not sure if this makes much sense:

    if($datefrom1 != '' && $dateto1 != '')
    {
        $datefrom=date("Y-m-d",strtotime($datefrom1));
        $dateto=date("Y-m-d",strtotime($dateto1));
    }
    else
    {
        $datefrom=$datefrom1;
        $dateto=$dateto1;
    }

What you're saying is - "If NEITHER datefrom1 NOR dateto1 are empty, reformat them and pass these values on to datefrom and dateto. However, if ANY are empty, pass both raw values (without reformatting) on to datefrom and dateto"

That makes little sense to me, but there again I have no idea about the input data or their format. You didn't share that information.

OK, so you seem to be using some DB abstraction class - no mention of what - is it from CI, Laravel or some other framework?

$datecondition is a variable - what's it doing there? If you want to add a 'where' filter/clause then I would assume you need to use something like...

$this->db->where(...)

I can't see how any of this would work or would filter your results, hence yoyu get the full whack of records.

$this->db->like('invoice_master.date',$this->input->post('invoice_id'));
$datecondition;

should probably be something more like this

$this->db->like('invoice_master.date',$datecondition);

of course given your question you should probably be using a between operator and have 2 date conditions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.