Jump to content

Archived

This topic is now archived and is closed to further replies.

JRS

Is the query possible

Recommended Posts

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 advance
JRS

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.