avoiding a switchstatement
| From: | hennink at patrijs dot max dot nl | Date: | Wed, 08 Nov 2000 15:05:33 +0000 |
| Subject: | avoiding a switchstatement | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24315@lists.php.net to get a copy of this message | ||
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.