Re: avoiding a switchstatement
| From: | John Meredith | Date: | Wed, 08 Nov 2000 15:30:31 +0000 |
| Subject: | Re: avoiding a switchstatement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24332@lists.php.net to get a copy of this message | ||
PHP includes a function called mysql_fetch_array() which should solve
your problem.
- John
On Wed, Nov 08, 2000 at 04:05:33PM +0100, hennink@patrijs.max.nl wrote:
> I've asked this before but didn't get any good results so another try.
> I've got a function that has to convert a mysql-result to an array.
> The problem is that $var can't be predicted so I can't use a
> switch-statement.
> Who knows a solution to this problem?????
>
> Tijmen
>
> * This function returns a array with all the results that are
> found
> * @param $var the name of the variabele that will be converted
> * @return $result an array that contains all the results
> */
> function resultToArray($var) {
> $size = mysql_num_rows($this->result);
> // $this->result contains a mysql-result
> $row = mysql_fetch_object($this->result);
> for($i=0;$i<$size;$i++) {
> // first sugestion
> $result[$i] = $row->{$var};
> // second sugestion
> $result[$i] = $row->$var;
> /*
> // this would be the normal solution but I don't
> want to insert a complete lexicon in here. ;-)
> switch($var) {
> case 'test':
> break;
> case 'test2':
> break;
> }*/
> }
> return $result;
> }
>
>
> --
> Tijmen Hennink
> Max.nl
> tijmen@max.nl
> tel : 055-5270270
> fax : 055-5270279
> ------------------------------------------------------------------------------
>
> Customer: I'm running Windows '98
> Tech: Yes.
> Customer: My computer isn't working now.
> Tech: Yes, you said that.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
John "Neutiquam erro" Meredith <johnm@psynix.com>