Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. When the CEO becomes a developer I

When the CEO becomes a developer I

Scheduled Pinned Locked Moved The Weird and The Wonderful
phpdatabasehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imagiro
    wrote on last edited by
    #1

    A company hired me for cleaning up the PHP-code the CEO created. The whole code reads like a how-not-to of programming, so I decided to post some of the gems here. This is the first one (I preserved all the formatting): MyCart::IsContentvalid() checks items in the cart against a database. Each call does 3 queries (per item!) of tables with around 500.000 entries. Note also the clever use of quotation marks.

     	  if(MyCart::IsContentvalid()==1)
      {
    
      Helper::Redirect("confirmation.php");
      }
      
      if(MyCart::IsContentvalid()==2)
      {
    
    $this->setErrorMsg("$curlang\[error\_msg1\]");
      }
    
      if(MyCart::IsContentvalid()==-12)
      {
    
    $this->setErrorMsg("These items can not be sold.");
      }
    
      if(MyCart::IsContentvalid()==15)
      {
    
    $this->setErrorMsg("Your account doesn't allow you to buy these items.");
      }
    
    
    else
      
      {
    
      	//Helper::Redirect("confirmation.php");
    	$this->setErrorMsg("$lang\[error\_msg2\]");
      }
    

    Oh, and the use of else is only for advanced programmers:

    if ($result == 1)
    {
    // do something here
    }
    if ($result != 1)
    {
    // do something else here
    }

    More will come soon!

    R 1 Reply Last reply
    0
    • I imagiro

      A company hired me for cleaning up the PHP-code the CEO created. The whole code reads like a how-not-to of programming, so I decided to post some of the gems here. This is the first one (I preserved all the formatting): MyCart::IsContentvalid() checks items in the cart against a database. Each call does 3 queries (per item!) of tables with around 500.000 entries. Note also the clever use of quotation marks.

       	  if(MyCart::IsContentvalid()==1)
        {
      
        Helper::Redirect("confirmation.php");
        }
        
        if(MyCart::IsContentvalid()==2)
        {
      
      $this->setErrorMsg("$curlang\[error\_msg1\]");
        }
      
        if(MyCart::IsContentvalid()==-12)
        {
      
      $this->setErrorMsg("These items can not be sold.");
        }
      
        if(MyCart::IsContentvalid()==15)
        {
      
      $this->setErrorMsg("Your account doesn't allow you to buy these items.");
        }
      
      
      else
        
        {
      
        	//Helper::Redirect("confirmation.php");
      	$this->setErrorMsg("$lang\[error\_msg2\]");
        }
      

      Oh, and the use of else is only for advanced programmers:

      if ($result == 1)
      {
      // do something here
      }
      if ($result != 1)
      {
      // do something else here
      }

      More will come soon!

      R Offline
      R Offline
      richard_k
      wrote on last edited by
      #2

      I **really** like the second one.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups