On Monday 21 January 2002 12:17, Alex Dowgailenko wrote:
> After getting very frustrated with arrays, I ended up using eval() in the
> following way:
>
> function top10() {
>       $i = 0;
>       $res = mysql_query("SELECT orders.pid, products.pid, orders.amount,
> products.pname FROM orders, products WHERE orders.uid!='' AND
> orders.pid=products.pid") or die(mysql_error());
>       while (list($opid, $ppid, $amount, $pname) = mysql_fetch_row($res)) {
>               $eval = '$temp["'.$pname.'"] = $temp["'.$pname.'"] + '.$amount.';';
>               eval($eval);
>               $i++;
>       }
>       arsort($temp);
>       return $temp;
> }

If you're using php4.03+ you could try:

  while ($row = mysql_fetch_assoc($res) {
    $temp[$row['pname']] = $row['pname'] + $row['amount'];
    $i++;
  }



-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Life is a sexually transmitted disease with 100% mortality.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to