JRS Posted May 1, 2006 Share Posted May 1, 2006 Hello,Not sure if this can be done. I have a set of numbers 1-100; Essentially they are tokens to be re-used again. I would like to be able to re-assign the lowest number that has been returned.So I'm looking to do a query all the numbers that are availabe or returned, basically the query is for something that does not exist. I only track the assigned tokens - once a token is returned - I delete from the db.Hope I made some sense. Thanks in advanceJRS Link to comment https://forums.phpfreaks.com/topic/8843-is-the-query-possible/ Share on other sites More sharing options...
kenrbnsn Posted May 1, 2006 Share Posted May 1, 2006 I came up with two ways of doing this. There may be more.[ol type=\'1\'][*][code]<?php$all_nums = range(1,100); // an array containing all of the numbers$q = "select token from tablename";$rs = mysql_query($q);while($rw = mysql_fetch_assoc($rs)) { $i = $rw['token'] - 1; // arrays start at index = 0 unset($all_nums[$i]); // remove token from the all_nums array$use = min($all_nums); // minimum of whats left?>[/code][*][code]<?php$all_nums = range(1,100); // an array containing all of the numbers$tmp = array(); // temporary array to hold the current tokens$q = "select token from tablename";$rs = mysql_query($q);while($rw = mysql_fetch_assoc($rs)) $tmp[] = $rw['token'];$diff = array_diff($all_nums, $tmp); // put the difference between the arrays in the array $diff$use = min($diff);?>[/code][/ol]Ken Link to comment https://forums.phpfreaks.com/topic/8843-is-the-query-possible/#findComment-32464 Share on other sites More sharing options...
JRS Posted May 2, 2006 Author Share Posted May 2, 2006 [!--quoteo(post=370400:date=May 1 2006, 05:12 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 1 2006, 05:12 PM) [snapback]370400[/snapback][/div][div class=\'quotemain\'][!--quotec--]I came up with two ways of doing this. There may be moreKen[/quote]Ken,Thanks a lot - I'll give those a try. It should do the trick.Much appreciated.JRS Link to comment https://forums.phpfreaks.com/topic/8843-is-the-query-possible/#findComment-32524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.