Click here to Skip to main content
15,885,045 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Bang Head! Pin
BillW3326-Jul-12 3:58
professionalBillW3326-Jul-12 3:58 
GeneralRe: Bang Head! Pin
Brisingr Aerowing28-Jul-12 3:30
professionalBrisingr Aerowing28-Jul-12 3:30 
GeneralRe: Bang Head! Pin
ExcellentOrg31-Jul-12 23:48
ExcellentOrg31-Jul-12 23:48 
GeneralRe: Bang Head! Pin
Brisingr Aerowing1-Aug-12 3:45
professionalBrisingr Aerowing1-Aug-12 3:45 
GeneralAnd this is why I hate PHP (again) PinPopular
Andrei Straut22-Jul-12 23:43
Andrei Straut22-Jul-12 23:43 
GeneralRe: And this is why I hate PHP (again) PinPopular
BobJanova23-Jul-12 4:02
BobJanova23-Jul-12 4:02 
GeneralRe: And this is why I hate PHP (again) Pin
Andrei Straut23-Jul-12 4:25
Andrei Straut23-Jul-12 4:25 
GeneralRe: And this is why I hate PHP (again) PinPopular
W Balboos, GHB30-Jul-12 1:33
W Balboos, GHB30-Jul-12 1:33 
I, on the contrary, really enjoy .php, but - being an amazingly nice guy (who NEVER eats bacon), I'll give you a watch-out-for:

If you are outputting results from an array (such as might be returned from dbase calls), you'll have any number of rowsets which might, for example, become the conents of a table. Let's say each rowset in array $Data contains such the fields 'recID', 'name', 'age', and you wish to iterate through a loop to generate a table.

You might try to use something like:

foreach ($Data as $d)
    ECHO "<tr><td>$d['recid']</td><td>$d['name']</td><td>$d['age']</td></tr>";

You'll typically get an error mentioning problems with whitespaces.
As it turns out, .php doesn't like the array item's referenced inside the "'s

The solutions are either:

foreach ($Data as $d)
    ECHO "<tr><td>".$d['recid']."</td><td>".$d['name']."</td><td>".$d['age']."</td></tr>";

or
foreach ($Data as $d) {
     $r = $d['recid'];
     $n = $d['name'];
     $a = $d['age'];
     ECHO "<tr><td>$r</td><td>$n</td><td>$a</td></tr>";
}

You may employ the later approach if you've other symbols you'd like in your "-ed output


"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010

GeneralRe: And this is why I hate PHP (again) Pin
Andrei Straut30-Jul-12 1:57
Andrei Straut30-Jul-12 1:57 
GeneralRe: And this is why I hate PHP (again) Pin
W Balboos, GHB30-Jul-12 2:43
W Balboos, GHB30-Jul-12 2:43 
GeneralRe: And this is why I hate PHP (again) Pin
Member 885702230-Jul-12 2:12
Member 885702230-Jul-12 2:12 
GeneralRe: And this is why I hate PHP (again) Pin
Moshe Katz30-Jul-12 4:09
Moshe Katz30-Jul-12 4:09 
GeneralRe: And this is why I hate PHP (again) Pin
BobJanova30-Jul-12 2:31
BobJanova30-Jul-12 2:31 
GeneralRe: And this is why I hate PHP (again) Pin
W Balboos, GHB30-Jul-12 2:34
W Balboos, GHB30-Jul-12 2:34 
GeneralRe: And this is why I hate PHP (again) Pin
ItsTobias30-Jul-12 2:47
ItsTobias30-Jul-12 2:47 
GeneralRe: And this is why I hate PHP (again) Pin
BobJanova31-Jul-12 0:18
BobJanova31-Jul-12 0:18 
GeneralRe: And this is why I hate PHP (again) Pin
ItsTobias31-Jul-12 0:35
ItsTobias31-Jul-12 0:35 
GeneralRe: And this is why I hate PHP (again) Pin
BobJanova1-Aug-12 0:11
BobJanova1-Aug-12 0:11 
GeneralRe: And this is why I hate PHP (again) Pin
ItsTobias1-Aug-12 0:34
ItsTobias1-Aug-12 0:34 
GeneralRe: And this is why I hate PHP (again) Pin
ItsTobias30-Jul-12 2:47
ItsTobias30-Jul-12 2:47 
GeneralRe: And this is why I hate PHP (again) Pin
leif neland3-Aug-12 2:41
leif neland3-Aug-12 2:41 
GeneralRe: And this is why I hate PHP (again) Pin
BobJanova3-Aug-12 4:59
BobJanova3-Aug-12 4:59 
GeneralRe: And this is why I hate PHP (again) Pin
OriginalGriff30-Jul-12 2:32
mveOriginalGriff30-Jul-12 2:32 
GeneralRe: And this is why I hate PHP (again) Pin
W Balboos, GHB30-Jul-12 3:33
W Balboos, GHB30-Jul-12 3:33 
AnswerRe: And this is why I hate PHP (again) Pin
Moshe Katz30-Jul-12 4:08
Moshe Katz30-Jul-12 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.