• (unregistered)

    What on earth is this monstrosity doing?

  • (cs)

    Wild...

  • (cs)

    What does the 'list' in while(list(... do?

    Drak 

  • (cs)

    Having developed in PHP for a few years now, I am shocked and appalled.

    But, I probably would be even if I hadn't.

    1. It would have been too easy to just "SELECT *" (unless there's another 500 columns or perhaps a few huge columns with data we don't need).  This is a minor point, and many probably will disagree.

    2) mysql_fetch_row (or PEARs DB abstraction class) has a nifty feature that returns a row of results in an associative array (ie, $row["value"])

    3) Should have created a function (or a hashtable at least if nothing more than stringcompares are going on) to translate "on" to "checked", etc.

    I've gotta get back to work, or the list would be longer..

  • (cs) in reply to Drak

    Re: "What does the 'list' in while(list(... do?"

    I haven't personally used that construct, and may be mistaken, but I believe it basically means "take the row from the result set, and copy the value of the first column into the first variable in the list, second column into second variable, etc"


  • (cs) in reply to Blue

    Ok, one more for now, can't help it...

    this part:
    $xa=$a;
    $xb=$b;
    $xc=$c;
    $xd=$d;
    $xe=$e;
    $xf=$f;

    and this part:
    if($xa == "on")
     $_a = "checked";

    Are truly the biggest WTFs of all!  "Hmm, let's take each value returned by our query, stuff its' value into SOME OTHER value, after all, more is better, right?  And while we're at it, let's create a THIRD variable to hold our interpretation of the copy of the first value.":

    OMFG!

  • (cs) in reply to Blue

    <FONT style="BACKGROUND-COLOR: #0000ff" color=#ffffff size=1>Re: "What does the 'list' in while(list(... do?"

    I haven't personally used that construct, and may be mistaken, but I believe it basically means "take the row from the result set, and copy the value of the first column into the first variable in the list, second column into second variable, etc"</FONT>

    Oh ok, thanks for explaining that. I still don't see what simple about this function though. Perhaps if you include it in every page it saves you from thinking or something?

    Drak

  • (unregistered) in reply to Blue

    It would be kind of understandable if the $a, $b, $c etc were scoped to the loop (they're not of course).

    And despite all the other WTFs, I can't fathom why a while loop is being used since only one row of data is being checked.

  • (unregistered)

    I see the light! 

    Now we can go back and fix that pesky uchar -> ushort conversion function!!

  • (cs)

    I wonder how short a good solution would be...I mean if you went from 650 lines to a mere 20 you could claim an impressive 32x improvement (its not often you can optimize a function that much...:).

    It seems the the DB table is just storing 219 columns of on/off data (are there two j9 a type?). Being a DB amateur, I'm wondering if there are any better (more efficient size wise and access wise) ways of storing such information. I might be tempted to just use bit fields but this would require some processing and not be extendable.

  • (cs)

    The real WTF is that he should have unrolled the while loop.

  • (cs)

    Does PHP have arrays?

  • (unregistered)

    Wow!  This guy must be a genius or something.

  • (cs)

    Why?

     

    WHY?

     

    Why does he need that many columns and why is he giving them those stupid names? A, B, C, ...

    Oh, wait... I get it!!! He's not really reading a database... He's reading rows from a spreadsheet, right? Spreadsheets just use letters (with additional digits) for column names. :-)

    But then what's that mySQL garbage sitting in this code?

     

    Why, oh why... This guy must have been nuts to come up with this...

  • (unregistered) in reply to Jeff S
    Jeff S:
    Does PHP have arrays?


    Certainly does!  [*-)]
  • (cs)

    If there were ever a time to use hideous php 'extract()' function, this would be it. It could have eliminated 95% of the code. This is a WTF on so many levels though, even a namespace poluting function like extract() really won't help anything.

  • (cs)

    <font face="Verdana" size="2">Till date, I have been reading WTFs but they never 'forced' me to comment. But this is just fricking ridiculous! God please forgive him, he doesn't know what he is doing.

    JD</font>

  • (unregistered)

    I've been developing in PHP for 6 years now and I've seen lots of crap, but this definitely beats it ALL

  • (unregistered) in reply to

    I am guessing this has something to do with checkboxes in an html page.[I]

    ie their values get submitted with default value of "on" (and for some reason saved to database like that)  The "on" values then get turned into "checked" so that these variables can be used in the html to set each individual checkbox on or off. <input type="checkbox"  $$$$ >   where $$$$ is "checked" or empty string

    That might answer the question of WHAT is this doing?

    But WHY is it being done this way still remains a mystery[8-)]

  • (unregistered) in reply to Katja

    Katja,

    is it 420 yet? 

  • (cs)

    .... Wow. Another post that just... defies description. That code is wrong on many many many levels. I could probably optimize it down to 15 lines or less. In fact... Here's my best go.

    (Note: I assume he's already selecting all the columns in the table. If that's not true, just change the query back to how it was.)

    [code language="c#"]
    include "../../../db.inc/db.inc.php";

    $result = mysql_fetch_array(mysql_query("SELECT * FROM gct WHERE casenum = '$aid'"));

    unset($result['casenum']);
    $xcontype = $result['contype'];
    unset($result['contype']);

    foreach ($result as $key => $value) {
    if ($value == 'on') {
    $varname = "_{$key}";
    $$varname = "checked":
    }
    }
    [/code]

    (It won't indent the code. Not sure why...)
  • (unregistered)

    Now here's another WTF everyone else seemed to miss:

    <font color="#990000">casenum, contype
    FROM gct WHERE casenum = '$aid'"

    </font>
    What's the point of grabbing the SAME column from the database as the one that is in the "WHERE" clause?

    The PHP list() function will "Assign variables as if they were an array".

    I FOUND THE PROBLEM WITH THE MINISCULE CODE!!!
    Some idiot that wrote the css stylesheet for this co-called "forum" placed this code in it:
    pre.source
    {
    <font color="#ff0000">font-size: 1em;</font>
    margin-left: 20px;
    color: black;
    font-family: Lucida Console, Courier New, Courier;
    background-color: gainsboro;
    }
    Maybe this forum should have it's own WTF threads!

    -- Never doubt the knowlege of 14-year-olds! [;)]
  • (cs) in reply to

    What's wrong with 1em? That's 'normal' size. The 'em' unit is relative to the default font size of the block.

  • (cs) in reply to

    :
    I FOUND THE PROBLEM WITH THE MINISCULE CODE!!!
    Some idiot that wrote the css stylesheet for this co-called "forum" placed this code in it:

    Thank you thank you! That sure as hell was an easy fix to make! I removed the 1 em from the CSS style sheet.

  • (unregistered) in reply to utoxin

    <FONT style="BACKGROUND-COLOR: #efefef">Yes, an "em" is related to the height of the letter "m" in the current font at the current size, which is certainly not the same as a size of 100%. It's probably more like saying "font-size: 50%" which is usually going to be too small.</FONT>

    <FONT style="BACKGROUND-COLOR: #efefef"></FONT> 

  • (cs) in reply to
    :

    <font style="background-color: rgb(239, 239, 239);">Yes, an "em" is related to the height of the letter "m" in the current font at the current size, which is certainly not the same as a size of 100%. It's probably more like saying "font-size: 50%" which is usually going to be too small.</font>

    <font style="background-color: rgb(239, 239, 239);"></font> 



    Huh. Never heard it explained that way. Thanks for the information.
  • (unregistered) in reply to

    Hmmm... the fix I suggested doesn't seem to work. Using my trusty Web

    Developer toolber, I played around with the css until i came up with a

    solution that seems to work well:


    Just under the pre.source, add this:

    pre

    {

        font-size: 1.2em;

    }


    On Firefox 1.0 it looks good.


    Just as a test case, I will show off the "before" and "after"

    Before
    <style>pre.testcase1 { font-size: 1.2em; }</style><style> pre.testcase2 { font-size: 1.3em; }</style>
    After
    After with 1.3em
  • (cs) in reply to

    <font face="Georgia">An em is related to the width, not the height, of a letter "m", so <font face="Courier New">font-size: 1em</font> is a no-op (ie it has no effect)... except if ten million other things come into play (handwaving wildly here since I never quite remember which bugs are part of the standard and which ones are IE's "improvements").

    So it's not that.  Good try though.  As soon as I've finished debugging some CSS and HTML written by monkeys for idiots (my day job) I'll take another look.  Honestly, it hadn't occurred to me that this piece of shite forum actually had any CSS...
    </font>

  • (unregistered) in reply to
    :

    <font style="background-color: rgb(239, 239, 239);">Yes, an "em" is related to the height of the letter "m" in the current font at the current size, which is certainly not the same as a size of 100%. It's probably more like saying "font-size: 50%" which is usually going to be too small.</font>



    No, that is wrong.

    The unit "em" is not related to the letter "m" in CSS.  It is the height of the font, so 1 is the normal size and 2 is twice as big. Click here for the CSS standard.  The tricky thing is that "em" when applied to the font-size property refers to the size of the font in the parent element.  That means if you have 0.5em nested twice, you actually get 0.25 the size of the parent font.

    The "em" used to be the size of the letter M, but in modern times that is no longer the case.  Not all fonts even have the letter M.  (Chinese language fonts for example.)

  • (cs) in reply to

    Ah, so my original definition was right. That makes me feel a little less confused. :)

  • (unregistered) in reply to bat
    bat:
    <font face="Georgia">An em is related to the width, not the height, of a letter "m"
    </font>


    You have it backwards.  It's the height of the font.  And not related to the letter "m."  Just the height of the font.  See the post above this one.

  • (unregistered) in reply to

    In defence of this crappy forum software, it may not work but looks good while it destroys your comments.

    Anonymous Defense League

  • (cs) in reply to Alex Papadimoulis
    Alex Papadimoulis:

    Thank you thank you! That sure as hell was an easy fix to make! I removed the 1 em from the CSS style sheet.

    Alex,

    Just a note to say thank-you to you.  I know that you hear a steady stream of negative remarks about the software that runs this forum but I wanted to tell you that this forum is providing a wonderful service to the community. 

    It's a refreshing dose of fun and discussion and a warning to all of us in the development arena that the quilty will ultimately be found and exposed.

    As for the other remarks, "Illegitemati non Carborundum"

  • (cs) in reply to Alex Papadimoulis
    Alex Papadimoulis:

    [image]  wrote:
    I FOUND THE PROBLEM WITH THE MINISCULE CODE!!!
    Some idiot that wrote the css stylesheet for this co-called "forum" placed this code in it:

    Thank you thank you! That sure as hell was an easy fix to make! I removed the 1 em from the CSS style sheet.

    And now all we wonder about is who the idiot was who put it there in the first place... Any clues, Alex? [;)]

  • (cs)

    <font face="Georgia">The greatest of all WTFs is what you're sure you know.

    From answers.com:
    </font>

    <font face="Verdana">In typography, a unit of measure equal to the width of the capital letter M in a particular font.</font>
    <font face="Georgia">That being said... how it actually comes together in CSS has only an incidental relation to this definition.
    </font>
  • (unregistered)

    (Without reading all 100k replies) Did this knucklehead get paid for writing this "code?"

    If so, I've found a new business model ;-)

  • (cs) in reply to Bustaz Kool
    Bustaz Kool:
    The real WTF is that he should have unrolled the while loop.


    Damn. Just when I was about to do my "unroll those loops..." mantra, he actually had a loop!

    So sad. [:'(]
  • (unregistered)

    for more on em and ex, see: http://kb.mozillazine.org/Em_vs._ex

  • (unregistered) in reply to
    :
    Now here's another WTF everyone else seemed to miss:
    <font color="#990000">casenum, contype
    FROM gct WHERE casenum = '$aid'"

    </font>
    What's the point of grabbing the SAME column from the database as the one that is in the "WHERE" clause?

    The PHP list() function will "Assign variables as if they were an array".

    I FOUND THE PROBLEM WITH THE MINISCULE CODE!!!
    Some idiot that wrote the css stylesheet for this co-called "forum" placed this code in it:
    pre.source
    {
    <font color="#ff0000">font-size: 1em;</font>
    margin-left: 20px;
    color: black;
    font-family: Lucida Console, Courier New, Courier;
    background-color: gainsboro;
    }
    Maybe this forum should have it's own WTF threads!

    -- Never doubt the knowlege of 14-year-olds! Wink
  • (unregistered) in reply to

    Moin,

    :
    Maybe this forum should have it's own WTF threads!

    It sure should. I just looked into the generated HTML code to locate your problem, and ... whooah .... There's something like seven layers of tables-in-tables, happily intermixed with CSS _and_ font tags in there.

    If I may list some of the WTFs that are less obvious than the table mêlée:
    * <img ... /> and <link ... /> are _wrong_ in HTML. (Well, there's SHORTTAGS, but no browser understands those anyway, and even that would be wrong here since these elements are defined to be empty.)
    * Comments may not include --, therefore <!-------FOO-------> is _wrong_.
    * The usual problem of forgotten "" in <font color=#F00>.
    * The usual problem of forgotten alt attributes in img elements.

    But back to the font-size issue. Of course 'font-size: 1em' is a no-op in CSS and shouldn't change anything. Giving any other value in em units may however yield unexpected results: The unit is relative to the font size of the surrounding element. So when applying it to a class and then nesting elements of this class in each other the effect multiplies.

    That's what's happening here: td.fh3a and td.txt4 (the names are WTFs in themselves) are roughly defined as font-size: 0.7em. The code is in a td.txt4 in a td.txt4 in a td.fh3a and therefore has a font-size of 0.7 times 0.7 times 0.7 equals 0.343em.

    And to add insult to injury: The f*ing thing just ate my reply when I tried a preview. I had to retype it.

    Update: I tried to post directly without preview but the darn thing replaced the text that I wrote with a full quote and no text. Sorry about that. Will try again with an Internet Explorer.

    --
    Henryk Plötz
    Grüße aus Berlin

  • (cs) in reply to

    :

    * Comments may not include --, therefore <!-------FOO-------> is _wrong_.

    Please read: http://www.htmlhelp.com/reference/wilbur/misc/comment.html

    I think that accordin to this, the comment you mentioned above is split out as:

    <!---- ---FOO-- ----->

    Which would be an empty comment, followed by a comment containing -FOO, followed by a comment containing -.

    This seems to be legal according to abovementioned document.

    But it's a WTF that you can put comments around your SCRIPT according to w3c, but no mention is made that you can then not use the '--' operator (i-- for example to subtract 1 from the value of i).

    Drak

  • (unregistered) in reply to Drak

    Moin,

    Drak:

    [image]  wrote:

    * Comments may not include --, therefore <!-------FOO-------> is _wrong_.

    Please read: http://www.htmlhelp.com/reference/wilbur/misc/comment.html

    Thanks, I didn't think of that, but I believe what I said is correct nevertheless. ;-)

    -- is the comment delimiter and thus can't be included in comments, while a comment is defined as everything between a pair of -- in a comment declaration.

    And incidentally my example (although not on purpose) as well as the code here break the rules.

    Drak:

    I think that accordin to this, the comment you mentioned above is split out as:

    <!---- ---FOO-- ----->

    Which would be an empty comment, followed by a comment containing -FOO, followed by a comment containing -.

    I don't think it works that way. My example should rather be split up as: empty comment, comment containing "-FOO", empty comment, "-" ... whoops.

    The wrong comment in the forum's code is <!-------- BEGIN ORIGINAL ----> which splits up as: empty comment, empty comment, "BEGIN ORIGINAL" ... whoops. Inserting an additional pair of -- around the BEGIN ORIGINAL makes the comment valid, though not good style (IMHO).

    --
    Henryk Plötz
    Grüße aus Berlin

  • (cs) in reply to Katja
    Katja:

    Why?

     

    WHY?

     

    Why does he need that many columns and why is he giving them those stupid names? A, B, C, ...

    Oh, wait... I get it!!! He's not really reading a database... He's reading rows from a spreadsheet, right? Spreadsheets just use letters (with additional digits) for column names. :-)

    But then what's that mySQL garbage sitting in this code?

     

    Why, oh why... This guy must have been nuts to come up with this...


    I doubt that. Spreadsheets use two letters (e.g. "AA") for columns beyond "Z".
  • (unregistered) in reply to bat

    Sorry to say this - - no not really - - but anyway, answers.com got that wrong. Just because they say they've got answers, doesn't mean they get'em all right...

    1. The definition was for lower-case 'm'.

    2. The definition is obsolete, meaning it is not used by publishing and printing companies anymore.

    3. The reason for the definition being changed (in the 80's I believe), was that it didn't yeild the same actual sizes at all printing companies, and it simply doesn't work for non-latin languages.

    The CSS spec use the exact same definition as any and all printing company you can find, call one and ask if you don't believe me...

     

    ::Ludvig A. Norin

  • (unregistered)

    This is actually very nice code. See, anyone even without programming knowledge can see what is going on in the code (at least after the seventh reading). Like Cobol, just written is PHP.

    The code is highly portable as well: no need to worry about the higher-level language features (like foreach or associative arrays) that might not be present in the version of PHP used. Assignment is always a safe bet. Sure, you might need a couple more lines and variables but with current computer speeds this is a non-issue. Premature optimization is the root of all evil.

    And maintainability: this is great. Even if during maintenance programming you manage to break one of the assignments, the others will continue to work just fine. Imagine if this were done with fancy associative arrays and stuff: one mistaek would render the whole system unusable!

  • (cs) in reply to

    :
    I don't think it works that way. My example should rather be split up as: empty comment, comment containing "-FOO", empty comment, "-" ... whoops.

    Hmm yes. You are right.. I guess it all depends on if the final parser is 'greedy' or not. If it's greedy it will try to find the longest possible comment, if not, it should break.. IE doesn't break so it might be greedy.

    Drak

  • (unregistered)

    Regarding the forum software: bahahaahahahaaaha.

    Regarding em's: http://css.nu/articles/typograph1-en.html#Ch23

  • (unregistered)

    Also: http://doubletype.sourceforge.net/?about%20em

  • (unregistered)

    Oh the horror!!  The pain!!!!

    I am also mad at the column names a, b, c etc. 

  • (unregistered)

    What's that giant nasty base64'd glob at the top of the source there for? I mean, while we're on the topic of the forum software.

Leave a comment on “Trust me, It's Easier This Way”

Log In or post as a guest

Replying to comment #:

« Return to Article