Gossamer Forum
Home : Products : Gossamer Links : Discussions :

retrieving and reusing last query

Quote Reply
retrieving and reusing last query
HI there,

I'm having a devil of a time trying to get my last query, so that I can slightly change and reuse it.

Here's the details.

What I'm doing is setting up my select query like this:

$db->select_options("Group by code Order by $sortby $sortorder");
$sth = $db->select ({'Username' => $user},["*", "LEFT(Add_Date,$date_range) as code","SUM(Grand_Total) as Grand_Total","count(*) as Customers" ],$acond3);

This works fine, and what I want to do next is this - change my select_options without having to rewrite the entire select statement again (I want to get the Grand_Total for all the items found).
$db->select_options("Group by Username Order by $sortby $sortorder");
$sth = $db->select(previous query INCLUDING the fields I previously stated I wanted, as well as the conditions found in $acond3.)


NOW the following variable contains only the last where, but it doesn't contain the entire query.
$db->select ($db->{'last_where'}) is just 'Username' => $user

The entire query is needed, because this second query returns 1 line grouped by User, but I also gives me SUM(Grand_Total) as Grand_Total that I'm ultimately after. (there are options to run about 16 different queries, and I need to know how to get the last query so I can rerun it with different select_options.

SO, where might one find the variable that contains the entire select statement, as opposed to just the last where clause, or does it exist?

thanks so much for any help you can provide.

peace.