PHP Wizards

From: Ken (SHIELDSIT)21 Apr 2011 13:17
To: Peter (BOUGHTONP) 86 of 101
Any idea why this would work:

code:
WHERE rudID='#form.batch#' AND rudCategory='Produced' AND rudProductID LIKE '%#WoodType#%' AND rudDescrip NOT LIKE '%boards%' AND rudDescrip NOT LIKE '%blocking%'


And this wouldn't?

code:
WHERE rudID='#form.batch#' AND rudCategory='Produced' AND rudProductID LIKE '%#WoodType#%' AND rudDescrip LIKE '%boards%' AND rudDescrip LIKE '%blocking%'


It tells me this:

quote:
Can't cast Complex Object Type Query to String
EDITED: 21 Apr 2011 13:19 by SHIELDSIT
From: Peter (BOUGHTONP)21 Apr 2011 13:42
To: Ken (SHIELDSIT) 87 of 101
It's not the NOTs that are making it not work (and if it was, they would give an SQL error instead).

The error message says you're trying to use a Query variable as if it were a String, and a query can't be implicitly converted (like numbers,booleans,etc can), so it falls over and complains.

Did you do the change in msg:38393.84 and/or anything else?

You've only got two variables shown, form.batch and WoodType - and neither of them should be queries based on the previous code, so either the code has changed, or the data has changed and is causing different behaviour in the code.

Is that definitely the line that the error is pointing to?
If so, are there any other variables inside the cfquery block?
From: Ken (SHIELDSIT)21 Apr 2011 13:47
To: Peter (BOUGHTONP) 88 of 101
No the only thing I changed was removing the NOT.

This works:
code:
<CFQUERY NAME="woodtype" DATASOURCE="isiswood">
	SELECT ID=rudID, Category=rudCategory, Seq=rudSeq, Type=rudType, Product_ID=rudProductID, Description=rudDescrip, 
	PcsPerPkg=rudPcsPerPkg, Tally=rudTally, UOM=rudBaseUnitID, Pieces=rudPieces, Volume=rudVolume, NetVolume=rudNetVolume, Cost=rudCost, AddedCost= rudAddedCost, MktValue=rudMarketValue, Total=rudTotal, NetThick=rudNetThick, 
	NetWidth=rudNetWidth, NetLength=rudNetLength, NetType=rudVolType, LocationID=rudLocationID,rudFIFOVolume,rudForceCost,rudBoomID,prdLengthID=(SELECT prdLengthID 
	FROM ProductMaster WHERE prdID=rudProductID) FROM ProductionDetail WHERE rudID='#form.batch#' AND rudCategory='Produced' AND rudProductID LIKE '%#WoodType#%' AND rudDescrip NOT LIKE '%boards%' AND rudDescrip NOT LIKE '%blocking%'
	ORDER BY Seq;
</cfquery>


This doesn't:
code:
<CFQUERY NAME="bandb" DATASOURCE="isiswood">
	SELECT ID=rudID, Category=rudCategory, Seq=rudSeq, Type=rudType, Product_ID=rudProductID, Description=rudDescrip, 
	PcsPerPkg=rudPcsPerPkg, Tally=rudTally, UOM=rudBaseUnitID, Pieces=rudPieces, Volume=rudVolume, NetVolume=rudNetVolume, Cost=rudCost, AddedCost= rudAddedCost, MktValue=rudMarketValue, Total=rudTotal, NetThick=rudNetThick, 
	NetWidth=rudNetWidth, NetLength=rudNetLength, NetType=rudVolType, LocationID=rudLocationID,rudFIFOVolume,rudForceCost,rudBoomID,prdLengthID=(SELECT prdLengthID 
	FROM ProductMaster WHERE prdID=rudProductID) FROM ProductionDetail WHERE rudID='#form.batch#' AND rudCategory='Produced' AND rudProductID LIKE '%#WoodType#%' AND rudDescrip LIKE '%boards%' OR rudDescrip LIKE '%blocking%'
	ORDER BY Seq;
</cfquery>
From: Peter (BOUGHTONP)21 Apr 2011 13:53
To: Ken (SHIELDSIT) 89 of 101

And the name of the query. :P

 

Do you happen to have both queries in the code, but the second query is after the first one?

 

Cus if so, once the first query has executed, the WoodType variable will be replaced with that query, and so the second one will fall over when it tries to use the original WoodType string.

 

(Which is exactly what the error is suggesting.)

 

A simple way to avoid it is to prefix or suffix all query variables, (so you could call it qryWoodType or WoodTypeQry and it wouldn't conflict with the original WoodType string), or you can give it a completely different name.

EDITED: 21 Apr 2011 13:54 by BOUGHTONP
From: Ken (SHIELDSIT)21 Apr 2011 13:57
To: Peter (BOUGHTONP) 90 of 101
I'm a dumbass. Thanks, that was it!
From: Ken (SHIELDSIT)23 Apr 2011 20:36
To: Peter (BOUGHTONP) 91 of 101
Pete you any good with the dates in CF? I need to search by month and year. I'm pretty sure I can use #LEFT and #MID. Is that how you would approach it?
From: Peter (BOUGHTONP)23 Apr 2011 21:11
To: Ken (SHIELDSIT) 92 of 101
Treat dates as dates, not strings. Convert to dates as soon as possible ( parseDate or parseDateTime ) and don't convert back to string until you have to.

If you're doing database date stuff, look up the native stuff ( DatePart or DateTrunc or whatever ), and use cfqueryparam with either cf_sql_date or cf_sql_timestamp (for dates/datetimes as appropriate).

Unless you've got *just* doing month and year stuff, in which case it's integers and Year and Month functions.
From: Ken (SHIELDSIT)25 Apr 2011 15:44
To: Peter (BOUGHTONP) 93 of 101
Do you have a few minutes today to assist me with searching for dates?
From: Voltane25 Apr 2011 16:32
To: Ken (SHIELDSIT) 94 of 101
I think it's a tall order asking Pete to find one date, let alone two...
From: Ken (SHIELDSIT)25 Apr 2011 16:33
To: Voltane 95 of 101

:')

 

Pete is a sexy man, he probably gets a lot of tail! (angel)

From: Ken (SHIELDSIT)25 Apr 2011 17:05
To: Voltane 96 of 101
I take that back! I got my query sorted on my own so Peter is no longer sexy!
From: Peter (BOUGHTONP)25 Apr 2011 19:39
To: Ken (SHIELDSIT) 97 of 101
Hey! :'(
From: Ken (SHIELDSIT)25 Apr 2011 20:05
To: Peter (BOUGHTONP) 98 of 101
(hug)
From: Ken (SHIELDSIT)26 Apr 2011 15:09
To: Peter (BOUGHTONP) 99 of 101

Pete do you know of a way to do this:

 

Say one of my users generates a report. I then ask them to add it to the monthly report. If they forget or something I want it to warn them if they click the back button or close the browser. Is there some Java or CF code that will do that?

From: Peter (BOUGHTONP)26 Apr 2011 16:13
To: Ken (SHIELDSIT) 100 of 101
YesNoMaybe. :P

What do you mean by "if they forget or something" - should the generated report always be added to the monthly report?

If so, just do it without asking them.

If not, under what conditions should it be added?

If those conditions can be determined in advance, make it a selection they do before even running the report.

(i.e. in general, give options to the user up-front, rather than bugging them with alerts after the fact.)

Anyway, for the functionality, it's main JavaScript you want (which is entirely different to Java, despite the similar names), though probably want a bit of CF too.

For closing the browser, the best you've got is the onunload JS event for the body, which will fire on more than just closing, but you can't avoid that.

For detecting back button, you'll want to set some flag on each request (e.g. a cookie), and then use JavaScript to call a webservice to check if that value is the latest one or an old one.

Not sure if that's explained very well, but don't have time for better right now... try googling it and someone might have an existing chunk of code you can use.
From: Ken (SHIELDSIT)26 Apr 2011 16:16
To: Peter (BOUGHTONP) 101 of 101
Good point. I think I will have it do it without asking if it isn't already in the database.