Jump to content

Hard to describe, I am looking for something like 'return' but for IF


cs.punk

Recommended Posts

Wrote something small just to get my point accross

 

<?php

if (isset($sumbited))
{//process form

   if (isset($error))
    {echo "Your username is too long";
      // at this point I would like it to go to the 'else' right below. @ Section 751
    }

}
else // THIS IS WHERE I WANT IT TO GO
{echo "blah blah"; // form data
}

?>

<?php
$done = 0;

if (isset($sumbited))
{//process form

   if (isset($error))
    {echo "Your username is too long";
    }
   else { $done = 1; }

}
if ($done == 0)
{echo "blah blah"; // form data
}

?>

 

edit: changed == 1 to == 0, typed it wrong originally

Instead of trying to make it go from that place to that other place, I think you need to rethink your structure.  You would normally use something like goto but that is spaghetti code programming and is bad practice.  What is your overall goal with this?

Goto?  Yuck!!!  If you must use a goto, set what you want to do in a function, and then call the function..  This helps document your code as you go too, and is one step closer to OOP.

 

 

function doSomething() {
      // THIS IS WHERE I WANT IT TO GO
     echo "Your username is too long";
     echo "blah blah"; // form data
}


/*** MAIN PROGRAM BODY ****/

if ($sumbited)
{//process form

   if ($error) {
       doSomething();
    }


}

 

or you could do

 

      if ( $submitted && $error ) {
             doSomething();
      }

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.