PHP Wizards

From: af (CAER)20 Apr 2011 18:14
To: Peter (BOUGHTONP) 63 of 101
quote:
TABS ARE YOUR FRIEND!
Identing blocks makes things MUCH easier to read.
(Although using eight space for it, like Firefox is doing above, is a tad annoying.)
WRONG :@

Spaces are your friend. Tabs* are evil.

* the ASCII #9 character
From: Peter (BOUGHTONP)20 Apr 2011 18:15
To: Ken (SHIELDSIT) 64 of 101
Oh crap, I always do that. :(

Change index="CurType" to item="CurType"
From: Peter (BOUGHTONP)20 Apr 2011 18:21
To: af (CAER) 65 of 101
Oh no, you're not one of those freaks are you!? :P

Tabs allow configurable indenting. Spaces don't.

Spaces are silly.

(Though still preferable to no indents at all.)
EDITED: 20 Apr 2011 18:22 by BOUGHTONP
From: af (CAER)20 Apr 2011 18:24
To: Peter (BOUGHTONP) 66 of 101

If you have a decent editor, spaces do allow configurable indenting. Plus they guarantee consistency of appearance, which is important when you're working with other people on a file and there is a mandated maximum line length.

 

(honestly though I don't care much - if I download some sample code that uses tab characters I just do :retab in Vim to convert them to spaces. Consistency is what's important)

EDITED: 20 Apr 2011 18:32 by CAER
From: Peter (BOUGHTONP)20 Apr 2011 18:35
To: af (CAER) 67 of 101
No they don't, they allow convertable indenting, because the editor needs to convert from actual to preferred (and probably back again when saving).

Tabs allow it to be done without touching the data.


Also, a "decent editor" could deal without any indenting (or newlines) at all - but we don't always have a decent editor to hand, so keeping the raw files with sensible whitespace makes far more sense.


quote:
they guarantee consistency of appearance, which is important when you're working with other people on a file and there is a mandated maximum line length.

WTF!? Who has maximum line lengths? This isn't 1970s any more.

Get a decent editor and you have:
1) horizontal scrollbars
2) working (soft) word wrap.

And get a decent language and structure and you'll almost never go beyond 100 characters wide anyway.
EDITED: 20 Apr 2011 18:38 by BOUGHTONP
From: Ken (SHIELDSIT)20 Apr 2011 18:35
To: Peter (BOUGHTONP) 68 of 101

Can't get it to work, but that's OK because I've confused myself to the point that I'm not sure what I'm trying to accomplish.

 

Fuck my head hurts!

From: Peter (BOUGHTONP)20 Apr 2011 18:38
To: Ken (SHIELDSIT) 69 of 101
Is it giving an error or just producing the wrong result?
From: Ken (SHIELDSIT)20 Apr 2011 18:43
To: Peter (BOUGHTONP) 70 of 101

error. but I'm stuck on trying to figure out how to approach this.

 

I have the needed info in the database. So I just need to compare or count and that's where I'm stuck atm.

From: Ken (SHIELDSIT)20 Apr 2011 18:55
To: Peter (BOUGHTONP) 71 of 101
OK Pete help me!

I have this:
code:
<CFQUERY NAME="count" DATASOURCE="isiswood">
	SELECT COUNT(*) AS WoodType 
	FROM ProductionDetail WHERE rudID='041811BD' AND rudCategory='Produced' AND rudProductID LIKE '%RO%';
</cfquery>


And it's working, but how can I automate this so I don't have to put every time of shit we have. It's already in the database.
From: af (CAER)20 Apr 2011 19:02
To: Peter (BOUGHTONP) 72 of 101
Max line length matters when I have 4 columns of code visible at once. Besides, I didn't make the rule.

You make a compelling argument in favour of tabs for indenting, though.
EDITED: 20 Apr 2011 19:03 by CAER
From: Peter (BOUGHTONP)20 Apr 2011 19:26
To: Ken (SHIELDSIT) 73 of 101
Which one is the actual wood type, the rudId ?

Try something along the lines of this:

code:
<CFQUERY NAME="count" DATASOURCE="isiswood">
	SELECT rudID AS WoodType, COUNT(*) AS WoodCount
	FROM ProductionDetail WHERE rudCategory='Produced' AND rudProductID LIKE '%RO%'
	GROUP BY rudID
</cfquery>
From: Ken (SHIELDSIT)20 Apr 2011 19:31
To: Peter (BOUGHTONP) 74 of 101
Well here's the thing. The %RO% could be about 20 different things. Should I just create a table to hold what they could be and use it to loop through?
From: Peter (BOUGHTONP)20 Apr 2011 19:44
To: Ken (SHIELDSIT) 75 of 101
Oh, so "RO" is one type of wood, but the ProductID contains other stuff in addition to that?

Is it always two characters at the same location?

If so, you can use mid or substring or whatever function MSSQL uses to do this... looks like it is SUBSTRING, so...

code:
SELECT SUBSTRING(rudProductID,6,2) AS WoodType, COUNT(*) AS WoodCount
FROM ProductionDetail WHERE rudCategory='Produced'
GROUP BY SUBSTRING(rudProductID,6,2)


If the RO (and similar values) changes position in the code then you can't do that, but probably they're in the same place?
EDITED: 20 Apr 2011 19:44 by BOUGHTONP
From: Ken (SHIELDSIT)20 Apr 2011 19:45
To: Peter (BOUGHTONP) 76 of 101
Nice! Yes always in the same spot. That should be saweet!
From: Ken (SHIELDSIT)20 Apr 2011 19:53
To: Peter (BOUGHTONP) 77 of 101
That worked like a charm! Thanks!
From: Ken (SHIELDSIT)20 Apr 2011 20:40
To: Peter (BOUGHTONP) 78 of 101

OK Peter I'm stuck again.

 

I can get it to output the types and count for a query, but how can I tell it the one with the biggest number is the one I want to use?

From: Ken (SHIELDSIT)20 Apr 2011 20:52
To: Peter (BOUGHTONP) 79 of 101
Nevermind I got it. Probably not the prettiest but it's working :)
From: Peter (BOUGHTONP)20 Apr 2011 22:37
To: Ken (SHIELDSIT) 80 of 101
Did you ORDER BY counted_column DESC or something more complicated?
From: Ken (SHIELDSIT)20 Apr 2011 22:48
To: Peter (BOUGHTONP) 81 of 101

I'll show you after I eat supper. I can't remember really.

 

But I rebuilt the whole code and cleaned it all up. It required much less math and variables. So I thank you for that! Plus I formatted it as you suggested and that helps a lot.

From: Ken (SHIELDSIT)20 Apr 2011 23:26
To: Peter (BOUGHTONP) 82 of 101
This is what I did. It let me eliminate a bunch of if's and other math.
code:
<CFQUERY NAME="sluth" 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>