Re: Simple Math

From: Date: Tue, 27 Jun 2000 17:49:59 +0000
Subject: Re: Simple Math
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3379@lists.php.net to get a copy of this message
Phillip S. Baker, > I know this is pretty basic, but I am not finding out how to do this > in the mathical functions area of the manual. > > I am pulling a list of items out of a DB using a while statement. > > Now I want to dynamically generate numbers for the list based on how > many items are pulled up, not based on an ID in the DB. > > So for the first item I would always liek to start with 1 and for the > next item that appears in the array to add one and so forth to get a > numbered list. > > How would I do this? Something like this: <?php $arr = array("foo", "bar", 2, 3); $list = array(); $siz = sizeof($arr); for ($i = 1; $i < $siz + 1; $i++) { $list[] = $i; } ?> I am not quite sure what you meant this 'list' but here I but it in an array called '$list' so that you can use it later. The array '$arr' was made just for the demonstration. You replace it with the data from the DB. You might also consider something like this if you're using MySQL: <?php $result = mysql_db_query("thedb", $query); $i = 0; while ($tmp = mysql_fetch_array($result)) { $i++; $list[] = $i; } ?> I don't know if any of this code will help you, but at least I gave it a shot :) -- Øyvind Grønnesby "Wow, I had knowledge!" --Buffy

« previous php.general (#3379) next »