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! Quote 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? Quote 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. Quote 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? Quote 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. Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.