On Sat, Mar 06, 2004 at 09:34:26AM -0500, Brian V Bonini wrote:
> > What to do?
> 
> function output($data_file)
> {
>     $file = file("data/$data_file.txt");
> 
>         foreach($file as $value ) {
>             $output .= "$value<br>";
>         }
> 
>     return $output;
> }
> 
> 
> switch($action) {
>   case "people":
>      output('people');
>      break;
>   case "industry":
>      output('industry');
>      break;
>   case "art"
>      output('art')
>      break;
>   case "animals":
>      output('animal');
>      break;
>   case "contact":
>      output('contact');
>      break;
> }

Hrm... why the switch() statement?  I can see the need for validating
user-submitted data, but to make it a little more flexible, maybe
something like this:

   <?php 
   function output($data_file)
   {
   # this doesn't change
   }
  
   $valid_actions = array('people', 'industry', 'art', 'animal', 'contact');
   $action        = $_GET['action'];
   if (in_array($action, $valid_actions)) {
     output($action)
   }
   else { 
     # handle error somehow
   }
   ?>

To add more valid actions, you can just extend the array of valid
actions, rather than adding clauses to the switch statement.

joel

-- 
[ joel boonstra | gospelcom.net ]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to