Jump to content


Photo

Is the query possible


  • Please log in to reply
2 replies to this topic

#1 JRS

JRS
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 01 May 2006 - 08:06 PM

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

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 01 May 2006 - 09:12 PM

I came up with two ways of doing this. There may be more.[ol type=\'1\'][*]
<?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
?>
[*]
<?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);
?>
[/ol]
Ken

#3 JRS

JRS
  • Members
  • PipPipPip
  • Advanced Member
  • 45 posts

Posted 02 May 2006 - 04:00 AM

[!--quoteo(post=370400:date=May 1 2006, 05:12 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 1 2006, 05:12 PM) View Post[/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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users