Jump to content

Is the query possible


JRS

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.