By: Ken Roberts
Date: 2005-02-12
Time: 00:18
|
Expressing variables inside a MergeBlock using MySQL......
Why can I not pass a simple variable into a MySQL statemnet within a MergeBlock. I have been banging my head on the wall trying to figure out what combination of delimiters or whatever I need to have in this statement to get it to read correctly.
If I put a static value in there, it works perfectly. Here is my latest rendition:
$agent = $HTTP_POST_VARS["agent"];
$startdate = $HTTP_POST_VARS["start_timestamp"];
$enddate = $HTTP_POST_VARS["end_timestamp"];
$type = $HTTP_POST_VARS["reservationtype"];
echo $agent;
echo $startdate;
echo $enddate;
echo $type;
include_once('tbs_class.php');
require('mysql_cnx.php');
$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('template.htm') ;
$TBS->MergeBlock('orders','mysql','SELECT id,agent_username,agent_name,customer_name,vendor_name,o_timestamp,a_timestamp,status,qty,pricesold,agent_commission,product_id FROM orders WHERE agent_username = $agent ') ;
$TBS->MergeBlock('products','mysql','SELECT id,type FROM products WHERE (id=%p1%)') ;
$TBS->MergeBlock('agent','mysql','SELECT * FROM agents WHERE username=$agent') ;
mysql_close($cnx_id) ;
$TBS->Show() ;
I am looking for $agent to be able to be placed inside MySQL statement in the first MergeBlock.
Any assistance would be greatly appreciated.
|
By: Ken Roberts
Date: 2005-02-12
Time: 01:05
|
Re: Expressing variables inside a MergeBlock using MySQL......
OK..... I have found the the answer......finally after looking through numerous posts unrelated to variables or mysql, I have found a snippet that has resolved my problem. It seems that you have to not only escape the quotes, but also break the variable outside of the MergeBlock.
This was accomplished by replacing with the following lines:
$TBS->MergeBlock('orders','mysql','SELECT id,agent_username,agent_name,customer_name,vendor_name,o_timestamp,a_timestamp,status,qty,pricesold,agent_commission,product_id FROM orders WHERE agent_username = \''.$agent.'\' ') ;
AND
$TBS->MergeBlock('agent','mysql','SELECT * FROM agents WHERE username=\''.$agent.'\'') ;
Hope this helps someone else...
|