Hi everybody !
I’m using CakePHP 2 and I have a table named Sales and 3 rows named Seller, Buyer and Price.
In a HTML page, I display the result of this query in a HTML table in myview.ctp :
public function myview() {
$this->set('mysales', $this-Sales>find('all',
array('sum(price)AS total','group' => array('seller_name','buyer_name'))));
}
In each line where the result is displayed, there’s a link which send the seller name and the buyer name of the line clicked and will help creating a PDF with the sale details :
<?php echo $this->Html->link("PDF", array(
"controller" => "name of controller",
"action" => "myview_pdf",
"?" => array(
"seller_name0" => $thesales['Sales']['seller_name'],
"buyer_name0" => $thesales['Sales']['buyer_name']
)
)); ?>
I got this function in the controller which receives the seller and buyer names of the line clicked :
public function myview_pdf(){
$this->set('seller_name1', $this->request->query("seller_name0"));
$this->set('buyer_name1', $this->request->query("buyer_name0"));
}
Now I want to do this SQL query :
SELECT detail1_of_sale, detail2_of_sale, detail3_of_sale, detail4_of_sale
FROM sales
WHERE seller_name = 'seller_name1', buyer_name = 'buyer_name1'
Which I hope will help me display the details of the sale involving seller_name1 and buyer_name1
What I tried to do is this (in the controller, function myview_pdf) :
$this->set('mysales', $this->Sales->find('all',
array(
'fields' => array('detail1_of_sale','detail2_of_sale','detail3_of_sale','detail4_of_sale'),
'conditions' => array(
'seller_name' => $seller_name1,
'AND' => array(
array(
'buyer_name' => $buyer_name1
)))
)
));
I don’t know if it’s a syntax mistake or what it just tells me that $seller_name1 and $buyer_name1 are undefined variables.
Note : When I take off the conditions, the $seller_name1 and $buyer_name1 are displayed correctly in myview_pdf.ctp with a simple echo.
Thanks for your help !