hoopplaya4 Posted December 7, 2008 Share Posted December 7, 2008 Hi all, I am looking for some help on selecting variables from MySQL, but leaving out the oldest (or smallest numerical) value. Let's say I have several values (which are auto-incremented) in the DB. For example: 32, 34, 35, 36, 38, 40. When I select these ID's from the Database, I'd like to select and echo all of them except the one which was first created. In the example above, it would be "32". How would I go about achieving something like this? Thanks! Link to comment https://forums.phpfreaks.com/topic/135948-solved-mysql-select-hopefully-simple/ Share on other sites More sharing options...
Flames Posted December 7, 2008 Share Posted December 7, 2008 why just not select id 32 then? Link to comment https://forums.phpfreaks.com/topic/135948-solved-mysql-select-hopefully-simple/#findComment-708659 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 In your sql query do an order by ID, then the following should help you with the logic $i=0; while ($row = mysql_fetch_assoc($result)) { if ($i == 0) { $i++; continue; // dont print the first id } echo $row['id']; } Hope that helps ya. Link to comment https://forums.phpfreaks.com/topic/135948-solved-mysql-select-hopefully-simple/#findComment-708662 Share on other sites More sharing options...
hoopplaya4 Posted December 7, 2008 Author Share Posted December 7, 2008 @Flames: The reason was because those numbers are dynamically generated. Thus, I won't always know what the number is. I was only using "32" as an example. Sorry for not being clear. @premiso: That did it, thanks for getting me in the right direction. However, I have one caveat, (and maybe I'm asking too much). In order to pull it off, I had to ORDER BY ASC. But, I'd actually like to display the variables in a descending fashion. Is this possible in my circumstance? Link to comment https://forums.phpfreaks.com/topic/135948-solved-mysql-select-hopefully-simple/#findComment-708672 Share on other sites More sharing options...
premiso Posted December 7, 2008 Share Posted December 7, 2008 @Flames: The reason was because those numbers are dynamically generated. Thus, I won't always know what the number is. I was only using "32" as an example. Sorry for not being clear. @premiso: That did it, thanks for getting me in the right direction. However, I have one caveat, (and maybe I'm asking too much). In order to pull it off, I had to ORDER BY ASC. But, I'd actually like to display the variables in a descending fashion. Is this possible in my circumstance? Just reverse the logic: $i=1; $cnt = mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { if ($i == $cnt) { continue; // dont print the first id } echo $row['id']; $i++; } Should do the trick. Link to comment https://forums.phpfreaks.com/topic/135948-solved-mysql-select-hopefully-simple/#findComment-708675 Share on other sites More sharing options...
hoopplaya4 Posted December 7, 2008 Author Share Posted December 7, 2008 That was it! Thank you very much. Learned something new. Link to comment https://forums.phpfreaks.com/topic/135948-solved-mysql-select-hopefully-simple/#findComment-708681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.