Forum Moderators: coopster
SELECT tblgroup.groupID, tblgroup.lastName, tblgroup.typeID, tblgroup.ageRangeID, tblgroup.timeID FROM tblgroup WHERE
(tblgroup.typeID = %s AND tblgroup.ageRangeID = %s AND tblgroup.timeID = %s)
I also had it set up with: .
"SELECT tblgroup.groupID, tblgroup.lastName, tblgroup.typeID, tblgroup.ageRangeID, tblgroup.timeID FROM tblgroup WHERE
(tblgroup.typeID = %s OR tblgroup.ageRangeID = %s OR tblgroup.timeID = %s)"
the results that get returned show all groups for all of the first variable that gets passed. I need a way to check for the first variable, then move to the second, then the third, if they are used. To me, it seems i need something like an "AND/OR" statement but don't think that is valid SQL. Can anyone advise?
For example..the process will be;
1. 1st query
2. get the query results and process it in PHP
3. forward the PHP processing results to 2nd mysql query (2nd variable)
Do this until all variables are processed. This makes your SQL query and php scripts looks very simple and easy to troubleshoot in case there are issues. You can even output the result using php echo in each step to see if that is exactly what you have expected.
it seems i would do something like:
SELECT * from TABLE WHERE condition = var 1, but don't see how i would get that result into another query.
sorry i am a noob at this. can you advise a bit further?
select="SELECT tblgroup.groupID, tblgroup.lastName, tblgroup.typeID, tblgroup.ageRangeID, tblgroup.timeID FROM tblgroup WHERE ("
if get("typeid")!="" then where=" AND tblgroup.typeID=" + get("typeid")
if get("ageRangeID")!="" then where=where +" AND tblgroup.ageRangeID=" + get("tblgroup.ageRangeID")
if get("timeID")!="" then where=where +" AND tblgroup.timeID=" + get("tblgroup.timeID")
/trim the first 'and' and add a closing paren.
query=select + substring(where,5) + ')'
SELECT *
FROM tblgroup
WHERE ("if varType !="" then WHERE = "tblgroup.typeID= varType" if varAge != "" then WHERE tblgroup.ageRangeID = varAge AND tblgroup.typeID = varType" if varTime != "" then WHERE tblgroup.timeID = varTime AND tblgroup.ageRangeID = varAge AND tblgroup.typeID = varType")
any advice?