Re: Array_walk

From: Date: Mon, 26 Jun 2000 22:32:44 +0000
Subject: Re: Array_walk
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3227@lists.php.net to get a copy of this message
One way to do it would be to perform only one query and then step through that... $books_list = implode (", ", $book); $query = "select title, price from books where bookid in ($books_list)"; $result = mysql_query ($query); while ($a = mysql_fetch_array ($result)) { echo "<tr><td>$a[title]</td>"; echo "<td>$a[price]</td></tr>"; $totalprice += $a[price]; } hope this helps, Ryan On Mon, Jun 26, 2000 at 08:34:25PM +0100, Phil Ahern wrote: > Hey All > > I have an array of id numbers on which I use the array_walk to search a > database of the for the relevant price and description of the id. What I > want to do is return the total price for all the id numbers in the array. > Anyone know how to do that or maybe a better way. The code is below.. > > function bookarraycheck($item) > { > > global $conn_id; > > $result = ifx_query("select title, price from books where bookid = > '$item'",$conn_id); > $r = ifx_fetch_row($result); > ifx_free_result ($result); > > echo "<TR><TD WIDTH=\"50%\" > VALIGN=\"TOP\">".$r["title"]."</TD>"; > echo "<TD WIDTH=\"50%\" VALIGN=\"TOP\">£ > ".$r["price"]."</TD></TR>"; > $totalcosts += $r["price"]; > > return $totalcosts; > > } > > array_walk( $book, 'bookarraycheck' ); > > > Thanks > > Phil > Caint.com > > > > > -- > 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 ---end quoted text---

« previous php.general (#3227) next »