> I am having a problem with this script It pulls a list of numbers from
> one field in the database (the numbers are in this format
> (275,277,278,276) It needs to pull each number and run it through the
> function dofunction and then move on to the next one in tell there are
> no more to process. What am I doing wrong or is there a better way to
> do this.
> 
> sql="Select Numbers from dom where name = '$name'";
> $results=safe_query($sql);
> $DBRow = mysql_fetch_array($results);
> $numbers = $DBRow["Numbers"];
> $numbers = array($numbers);
>   for($i = 0; $i < count($numbers); $i++) {
>       $number = $numbers[$i];
>       dofunction($number);
>   }

You have a few problems in your code. This hasn't been tested, but, is a
start...

sql="Select Numbers from dom where name = '$name'";
$results=safe_query($sql);
$DBRow = mysql_fetch_array($results);
$number_array = explode(",", $DBRow["Numbers"]);
// above splits number list into array using comma as delimiter

   foreach($number_array as $digit) {
         dofunction($digit);
    }

Above foreach() construct loops through the array and assigns the value of
each element to $digit, and continues doing this until it reaches the end of
the array.

http://www.php.net/manual/en/control-structures.foreach.php
http://www.php.net/manual/en/function.explode.php

Monty




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

Reply via email to