0

I have a view like that: enter image description here

What I want is when I click on the button, it will execute a select query:

SELECT discounts.product_id, products.product_name,
sum(products.product_price - discounts.product_discount) as total_Amount,
count(orders.order_id) as total_Number
FROM products 
inner join discounts on products.product_id = discounts.product_id
inner join orders on discounts.discount_id = orders.discount_id

where discounts.start_time >= **FromTextBox** and discounts.end_time <= **ToTextBox**

group by discounts.product_id,products.product_name

FromTextBox and ToTextBox are values from 2 textboxes.

This is in my controller:

....
$option['fields']= array('Discount.product_id','Product.product_name','benefit','number');
    //$option['conditions']=array('Discount.start_time >'=>array(''));  //where I put values from view
    $option['group'] = array('Discount.product_id','Product.product_name');
    $products = $this->Order->find('all',$option);
    $this->set('products',$products);

And my view:

<label class="control-label">From</label>
<div class="controls input-append date" id="dp1" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                <input size="16" type="text" value="" readonly>   <-- where I put textbox
                <span class="add-on"><i class="icon-remove"></i></span>
                <span class="add-on"><i class="icon-th"></i></span>
</div>
<label class="control-label">To</label>
<div class="controls input-append date" id="dp2" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                <input size="16" type="text" value="" readonly>   <-- where I put textbox
                <span class="add-on"><i class="icon-remove"></i></span>
                <span class="add-on"><i class="icon-th"></i></span>
</div>
 <div>
    <?php echo $this->Form->button('A Button'); ?>
</div>

Two textboxes are used Bootstrap datepicker. Please help me! thanks in advance.

1 Answer 1

2

You should use "Ajax" to send what is selected in "datepicker" to server, execute your query and use the result to create your table. There is no direct way in cakephp for your problem

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

2 Comments

thank you for your answer. is there any example for that? I am kind of new to cakephp.
I dont have a sample code for this. There is a jquery plugin "datatable". See the server side configuration and datefilter. I think your requirement is almost the same. datatables.net/examples/data_sources/server_side.html jquery-datatables-column-filter.googlecode.com/svn/trunk/….

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.