Re: Re: Multiple queries in PHP

From: Date: Sun, 25 Jan 2009 21:19:52 +0000
Subject: Re: Re: Multiple queries in PHP
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-287119@lists.php.net to get a copy of this message
On Sun, 2009-01-25 at 15:07 -0600, Shawn McKenzie wrote: > Ashley Sheridan wrote: > > Hi all, > > > > I've run into a bit of a problem. I put together a query using mysql > > variables in the form set @m:= 0; with the select that uses it directly > > after. For any wondering, the select was using it as an incremental > > value which can't be hard coded, as the value will depend on the > > ordering of the results of the query itself. > > > > The problem seems to be that while phpMyAdmin would execute this double > > query perfectly well, php using mysql_query() was having problems, as > > apparently it can't actually run multiple queries. > > > > Now the full query looks something like this: > > > > > > mysql_query("SELECT @m:=0;"); > > > > $query = "SELECT * FROM( > > SELECT profiles.id, ROUND(AVG(rated.score)) AS rating, > > COUNT(rated.score) AS total, @m:=@m+1 AS rank FROM > > rated LEFT JOIN > > profiles ON (profiles.id = rated.profile_id) GROUP BY > > rated.profile_id > > ORDER BY rating DESC, total DESC) AS ranking WHERE ranking.id=$id"; > > $result = mysql_query($query); > > > > > > which seems to be working OK so far, but does anyone know of any > > potential pitfalls I might face when doing something like this? > > > > Thanks, > > > > > > Ash > > www.ashleysheridan.co.uk > > > > Might try the mysqli extension. mysqli_multi_query() > > -- > Thanks! > -Shawn > http://www.spidean.com > Unfortunately, I think the server this is going on to doesn't have that extension :( Ash www.ashleysheridan.co.uk

« previous php.general (#287119) next »