Re: MySQL query help

From: Date: Mon, 10 Sep 2001 20:59:36 +0000
Subject: Re: MySQL query help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-66814@lists.php.net to get a copy of this message
Well, I played with this a little more and it seems to be acting oddly when you first call this select unless you set the variable first. So if the below doesn't work try actually doing this $query="set @count=NULL; select tableName.*,if(@count,@count:=@count+1,@count:=1) as inc, from tableName"; (I also realized that simply having @count as the test value should work as it should default to NULL) If I don't set it, it just returns 1 on every row. Anyone know why it is doing this? (I am Running MySQL 3.23.36) Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com ----- Original Message ----- From: "Sheridan Saint-Michel" <webmaster@foxjet.com> To: "Michael George" <george@mintcity.com>; <php-general@lists.php.net> Sent: Monday, September 10, 2001 3:29 PM Subject: Re: [PHP] MySQL query help > See if this does what you are shooting for: > > select tableName.*,if(@count>=1,@count:=@count+1,@count:=1) as inc, from > tableName; > > Keep in mind that @count will keep it's value until the thread is closed, so > if for some reason you have > to do the above twice in one thread throw in a statement like: > > set @count=Null; > > between the selects =P > > Sheridan Saint-Michel > Website Administrator > FoxJet, an ITW Company > www.foxjet.com > > > ----- Original Message ----- > From: "Michael George" <george@mintcity.com> > To: <php-general@lists.php.net> > Sent: Monday, September 10, 2001 2:20 PM > Subject: [PHP] MySQL query help > > > > I'm trying to make a query that will number it's own output rows. e.g. > when > > listing all the entries in a table that are related to a specific invoice, > > there will be a column with a monotonically increasing integer value (1-x > > where x is the number of matching entries). > > > > I know I can easily do this with PHP after the query is generated, but I > have > > a generic function to create a pulldown menu selection that will work > easily > > if I can just get that counter column in there... > > > > I've tried: > > > > select tableName.*, 1 as inc, sum( inc ) from tableName; > > > > But sum() will only accept a table column, not a display column... I have > the > > Widenius MySQL book, but I haven't found anything useful in there. > > > > If anyone has an idea, I'd appreciate it... > > > > -Michael > > > > -- > > No, my friend, the way to have good and safe government, is not to trust > it > > all to one, but to divide it among the many, distributing to every one > exactly > > the functions he is competent to. It is by dividing and subdividing these > > republics from the national one down through all its subordinations, until > it > > ends in the administration of every man's farm by himself; by placing > under > > every one what his own eye may superintend, that all will be done for the > > best. > > -- Thomas Jefferson, to Joseph Cabell, 1816 > > > > -- > > 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 > > > -- > 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

« previous php.general (#66814) next »