Skip navigation.

PHP's limited MySQL and math functionality...

Wonky Code

I've been using PHP for about 5 years and I like it a lot. However, two of my biggest complaints is that it has limited MySQL functionality and limited arithmetic operators. This isn't really a WTF but an example of what should be fixed in PHP.

I pray to the PHP gods! Please let me select a single field from a table! Please give me the modulus operator! I beg of thee!

Thanks to Wonko for sending this in.

= mysql_fetch_array(mysql_query("SELECT * FROM map WHERE x=".$minX." AND y=".$minY." LIMIT 1")) or die(mysql_error());
$j = $ix['id'];
$i = 1;
$opp = "";
while (
$i <= 625)
$opp .= "<input type='checkbox' name='d".$j."' value='1'>";
   if (
$i==25 || $i==50 || $i==75 || $i==100 || $i==125 || $i==150 || $i==175 || $i==200 || $i==225 ||
$i==250 || $i==275 || $i==300|| $i==325 || $i==350 || $i==375 || $i==400 || $i==425 ||
$i==450 || $i==475 || $i==500 || $i==525 || $i==550 || $i==575 || $i==600 || $i==625)
$opp .= "<br>\r\n";
$j = $j+226;

On another note. The site will be moving to Drupal. I've migrated over all the posts and the comments and putting together the PHPWTF theme for it. It should be done by next week. The change will bring some notable improvements.

  1. Automatic PHP Code highlighting
  2. Threaded Comment support
  3. WYSIWYG HTML comment support
  4. Clean URL's
  5. Better platform to develop new stuff

If you have any suggestions feel free to submit to them to [email protected], or you can just use the Submit WTF form. It all goes to the same place.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Err, PHP DOES have a modulus operator...

Selecting a single field from a table is SQL, *shifty eyes* SELECT * FROM table WHERE what='what' .

Do you have any other complaints that have already been solved?
DROP Wonko FROM building WHERE compalaints='stupid'

I think you guys are missing the sarcasm.

Yeesh, there's always one.
Or, in this case, two. I lament PHP's lack of sarcasm detection.

Other WTFs:
- No error checking at all.
- Why does $j get incremented by 226? Why isn't += used when it is?
- Why the hell is this code generating a 25x25 block of unlabeled checkboxes in the first place? Is this some sort of demented B&W graphic editor implemented in PHP & HTML?
- Why is "\r\n" used as a line ending after the <br>? Is this supposed to run on Windows?

Coding PHP for 5 years and you don't know about the modulus operator? :D

And what exactly is limited about the MySQL functionality?

It sure is a WTF to me hehe

the biggest wtf here are the comments...

Hey parkaybutter,
maybe some day you will learn the difference between a field and a record

Was this your code? :)

i saw this and almost puked.

PHP's always had a modulus op

PHP's always had a modulus operator: %

I bet he, or a maintenence

I bet he, or a maintenence programmer of similar skill, would break down and cry if he had to expand it to a 37x37 array. xD

Psh, I guess even having to scroll through a page of comments isn't enough to make peoples' sarcasm detection override their white knight syndrome. Though it is funny seeing people who live in a void where their post is still unique and useful. :p

Oh, I completely forgot. The

Oh, I completely forgot. The whole storing stuff in a string to spit it out when you're done makes scripting language designers cry. If you absolutely must have this, for headers or whatever, use output buffering. Never invent your own buffering, the string reallocations can kill your speed.

roflol since I found thephpwt

since I found thephpwtf and dailywtf I cannot stop laughing. Up to now I mostly read the rssfeeds, but I need to read the comments now. Maybe I start the commentwtf of thephpwtf :) realy great guys

> Why does $j get incremented by 226? Why isn't += used when it is?
or why doesnt he use $j++; 226times?

Post new comment


  • Web and e-mail addresses are automatically converted into links.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <p> <br /> <br>