Re: Re: eval()

From: Date: Mon, 21 Jan 2002 04:47:29 +0000
Subject: Re: Re: eval()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-82280@lists.php.net to get a copy of this message
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. */

« previous php.general (#82280) next »