Skip navigation.
Home

Wonky Code

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.

echo "using echo sucks!";

Wonky Code

Nicely formatted, easy to read, but oh so wrong. The switch is bad enough but using all those echo makes me so angry. I pity all pour souls that have to work with code like this.

<?php
if(@$_POST['vote'] == TRUE)
{
   switch (@
$_POST['bewertung'])
       {
           case
"1":
             
$punkt = 1;
             break;
           case
"2":
             
$punkt = 2;
             break;
           case
"3":
             
$punkt = 3;
             break;
           case
"4":
             
$punkt = 4;
             break;
           case
"5":
             
$punkt = 5;
             break;
            case
"6":
             
$punkt = 6;
             break;
            case
"7":
             
$punkt = 7;
             break;
           case
"8":
             
$punkt = 8;
             break;
             case
"9":
             
$punkt = 9;
             break;
             case
"10":
             
$punkt = 10;
             break;
         }
mysql_query("INSERT INTO bewertung(repID,punkte) VALUES ('$repID','$punkt')");
}

/* hier kommt nur die Ausgabe der Puntkte nich relevant*/

echo "<table border=0 width=80 cellspacinng=0 cellpadding=0>";
echo
"  <tr>";
echo
"   <td>";
echo
"     <form method=\"post\" type=\"text/css\" action=\"http://www.example.com/index.php?section=Replays\">";
echo
"        <select name=\"bewertung\" size=\"1\">";
             for (
$bew = 1 ; $bew &lt;= 10 ; $bew++)
                     {
                       echo
"<option>".$bew."</option>";
                     }
echo
"   </td>";
echo
"   <td>";
echo
"              <input type=\"submit\" value=\"Vote\" name=\"vote\">";
echo
"            </form>";
echo
"   </td>";
echo
"  </tr>";
echo
"</table>";
?>
XML feed